From fe8d893b839e9b14e3e55a3a0523cc1e6355bdd5 Mon Sep 17 00:00:00 2001 From: Thibault Leruitte Date: Tue, 26 Feb 2013 11:14:27 +0100 Subject: feat($compile): allow directives to modify interpolated attributes A directive can now set/update/remove attribute values even those containing interpolation during the compile phase and have the new value be picked up during the compilation. For example in template:
the replace-directive can now replace the value of some-attr-or-directive during compilation which produces this intermitent template: or even as well as --- test/ng/compileSpec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/ng/compileSpec.js') diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index f81199cb..9614030c 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -1503,6 +1503,12 @@ describe('$compile', function() { expect(attr.$observe('someAttr', observeSpy)).toBe(observeSpy); }; }); + directive('replaceSomeAttr', valueFn({ + compile: function(element, attr) { + attr.$set('someAttr', 'bar-{{1+1}}'); + expect(element).toBe(attr.$$element); + } + })); })); @@ -1544,6 +1550,14 @@ describe('$compile', function() { })); + it('should allow directive to replace interpolated attributes before attr interpolation compilation', inject( + function($compile, $rootScope) { + element = $compile('')($rootScope); + $rootScope.$digest(); + expect(element.attr('some-attr')).toEqual('bar-2'); + })); + + it('should call observer of non-interpolated attr through $evalAsync', inject(function($rootScope, $compile) { $compile('')($rootScope); -- cgit v1.2.3