Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

javascript - Angular JS custom delimiter

How do I use a custom delimiter for angular JS? I'd like to change from the {{ var }} syntax to [[ var ]].

Can somebody show me a complete example on how to implement this with Angular?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use $interpolateProvider to change start / end symbols used for AngularJS expressions:

var myApp = angular.module('myApp', [], function($interpolateProvider) {
    $interpolateProvider.startSymbol('[[');
    $interpolateProvider.endSymbol(']]');
});

and then, in your template:

Hello, [[name]]

Here is the working jsFiddle: http://jsfiddle.net/Bvc62/3/

Check the documentation on the $interpolate service here: http://docs.angularjs.org/api/ng.$interpolate


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...