diff options
| author | Igor Minar | 2012-08-11 00:13:10 -0700 |
|---|---|---|
| committer | Igor Minar | 2012-08-13 14:35:32 -0700 |
| commit | 7d77de283404d486ae3b21df69704894905ff8a7 (patch) | |
| tree | d05960d583f58abbf73262b5cdb9ae04dec0c063 /test/ng/compileSpec.js | |
| parent | ab044cada685fb36c73fa3cb7004e613105e6a4c (diff) | |
| download | angular.js-7d77de283404d486ae3b21df69704894905ff8a7.tar.bz2 | |
fix($compile): denormalize directive templates
Since developers are allowed to customize start/end interpolation
strings, but third-party directive creators don't know about these
customizations, we should standardize on {{ }} in templates of
reusable (third-party) directives. During the compilation, these
templates are then denormalized to use whatever the custom
start/end symbol is, effectively translating the template into the
syntax of the runtime environment.
This addresses an issue raised at http://goo.gl/e8VPV
Existing code should not be affected by this change since project
that do use custom interpolation markers are not expected to use
{{ }} in existing directive templates.
Diffstat (limited to 'test/ng/compileSpec.js')
| -rw-r--r-- | test/ng/compileSpec.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index cbf84a38..3d6144ac 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -1372,6 +1372,47 @@ describe('$compile', function() { '<option>Greet Misko!</option>' + '</select>'); })); + + + it('should support custom start/end interpolation symbols in template and directive template', + function() { + module(function($interpolateProvider, $compileProvider) { + $interpolateProvider.startSymbol('##').endSymbol(']]'); + $compileProvider.directive('myDirective', function() { + return { + template: '<span>{{hello}}|{{hello|uppercase}}</span>' + }; + }); + }); + + inject(function($compile, $rootScope) { + element = $compile('<div>##hello|uppercase]]|<div my-directive></div></div>')($rootScope); + $rootScope.hello = 'ahoj'; + $rootScope.$digest(); + expect(element.text()).toBe('AHOJ|ahoj|AHOJ'); + }); + }); + + + it('should support custom start/end interpolation symbols in async directive template', + function() { + module(function($interpolateProvider, $compileProvider) { + $interpolateProvider.startSymbol('##').endSymbol(']]'); + $compileProvider.directive('myDirective', function() { + return { + templateUrl: 'myDirective.html' + }; + }); + }); + + inject(function($compile, $rootScope, $templateCache) { + $templateCache.put('myDirective.html', '<span>{{hello}}|{{hello|uppercase}}</span>'); + element = $compile('<div>##hello|uppercase]]|<div my-directive></div></div>')($rootScope); + $rootScope.hello = 'ahoj'; + $rootScope.$digest(); + expect(element.text()).toBe('AHOJ|ahoj|AHOJ'); + }); + }); }); |
