From 30a8b7d0b5d4882c2bf3b20eb696a02f5b667726 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 10 Dec 2013 16:46:29 -0800 Subject: fix(ngInclude): Add template to DOM before linking other directives The template needs to be added to the DOM before other directives at the same element as `ngInclude` are linked. Fixes #5247. --- test/ng/directive/ngIncludeSpec.js | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test') diff --git a/test/ng/directive/ngIncludeSpec.js b/test/ng/directive/ngIncludeSpec.js index 2d115e8b..9e0a47b0 100644 --- a/test/ng/directive/ngIncludeSpec.js +++ b/test/ng/directive/ngIncludeSpec.js @@ -524,6 +524,46 @@ describe('ngInclude and transcludes', function() { }); }); + + it('should link directives on the same element after the content has been loaded', function() { + var contentOnLink; + module(function() { + directive('test', function() { + return { + link: function(scope, element) { + contentOnLink = element.text(); + } + }; + }); + }); + inject(function($compile, $rootScope, $httpBackend) { + $httpBackend.expectGET('include.html').respond('someContent'); + element = $compile('
')($rootScope); + $rootScope.$apply(); + $httpBackend.flush(); + expect(contentOnLink).toBe('someContent'); + }); + }); + + it('should add the content to the element before compiling it', function() { + var root; + module(function() { + directive('test', function() { + return { + link: function(scope, element) { + root = element.parent().parent(); + } + }; + }); + }); + inject(function($compile, $rootScope, $httpBackend) { + $httpBackend.expectGET('include.html').respond(''); + element = $compile('
')($rootScope); + $rootScope.$apply(); + $httpBackend.flush(); + expect(root[0]).toBe(element[0]); + }); + }); }); describe('ngInclude animations', function() { -- cgit v1.2.3