From 66f051386e153f10bd2751a7cafb61404799adee Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Tue, 8 Jan 2013 20:11:51 +0100 Subject: 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). --- test/ng/compileSpec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index a002171b..363b4329 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -298,6 +298,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('