fix(ngView): 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 `ngView` are linked.

Related to #5247.
This commit is contained in:
Tobias Bosch
2013-12-10 16:45:54 -08:00
parent 43072e3812
commit f8944efe70
2 changed files with 87 additions and 27 deletions

View File

@@ -582,6 +582,46 @@ describe('ngView and transcludes', function() {
});
});
it('should link directives on the same element after the content has been loaded', function() {
var contentOnLink;
module(function($compileProvider, $routeProvider) {
$routeProvider.when('/view', {template: 'someContent'});
$compileProvider.directive('test', function() {
return {
link: function(scope, element) {
contentOnLink = element.text();
}
};
});
});
inject(function($compile, $rootScope, $location) {
element = $compile('<div><div ng-view test></div>')($rootScope);
$location.url('/view');
$rootScope.$apply();
expect(contentOnLink).toBe('someContent');
});
});
it('should add the content to the element before compiling it', function() {
var root;
module(function($compileProvider, $routeProvider) {
$routeProvider.when('/view', {template: '<span test></span>'});
$compileProvider.directive('test', function() {
return {
link: function(scope, element) {
root = element.parent().parent();
}
};
});
});
inject(function($compile, $rootScope, $location) {
element = $compile('<div><div ng-view></div>')($rootScope);
$location.url('/view');
$rootScope.$apply();
expect(root[0]).toBe(element[0]);
});
});
});
describe('ngView animations', function() {