Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 635
Azri Jamil Avatar asked Oct 16 '12 21:10

Azri Jamil


People also ask

What is attrs in AngularJS?

scope is an AngularJS scope object. element is the jqLite-wrapped element that this directive matches. attrs is a hash object with key-value pairs of normalized attribute names and their corresponding attribute values. controller is the directive's required controller instance(s) or its own controller (if any).

What is restrict in AngularJS directive?

Restrict. Angular allows us to set a property named restrict on the object we return on our directive definition. We can pass through a string with certain letters letting Angular know how our directive can be used. function MyDirective() { return { restrict: 'E', template: '<div>Hello world!


1 Answers

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

like image 99
pkozlowski.opensource Avatar answered Oct 12 '22 01:10

pkozlowski.opensource