diff options
| author | Martin Probst | 2013-01-08 20:11:51 +0100 |
|---|---|---|
| committer | Igor Minar | 2013-01-09 20:06:22 -0800 |
| commit | cdf6fb19c85560b30607e71dc2b19fde54760faa (patch) | |
| tree | 031f53d0850ccd1f5cec38f1ed1f7bd04e7cc1ab /test/ng | |
| parent | c909f491125d4c846782cf4d5d98bb366aec8c3f (diff) | |
| download | angular.js-cdf6fb19c85560b30607e71dc2b19fde54760faa.tar.bz2 | |
feat($compile): support modifying the DOM structure in postlink fn
Support modifying the DOM structure in the post link function of a directive
by creating a defensive copy of the node list, as opposed to a live DOM list.
This is useful for directives to actually replace their entire DOM fragment,
e.g. with the HTML fragment generated by a 3rd party component (Closure, Bootstrap ...).
Fix the indentation of the compileNodes function (was one too little).
Diffstat (limited to 'test/ng')
| -rw-r--r-- | test/ng/compileSpec.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 75af0181..5b644af9 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -285,6 +285,25 @@ describe('$compile', function() { expect(log).toEqual('LOG; LOG'); }); }); + + + it('should allow modifying the DOM structure in post link fn', function() { + module(function() { + directive('removeNode', valueFn({ + link: function($scope, $element) { + $element.remove(); + } + })); + }); + inject(function($compile, $rootScope) { + element = jqLite('<div><div remove-node></div><div>{{test}}</div></div>'); + $rootScope.test = 'Hello'; + $compile(element)($rootScope); + $rootScope.$digest(); + expect(element.children().length).toBe(1); + expect(element.text()).toBe('Hello'); + }); + }) }); describe('compiler control', function() { |
