mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 03:30:02 +08:00
fix($compile): pass transcludeFn down to nested transclude directives
If you have two directives that both expect to receive transcluded content
the outer directive works but the inner directive never receives a
transclusion function. This only failed if the first transclude directive
was not the first directive found in compilation.
Handles the regression identified in e994259739
Fixes #7240
Closes #7387
This commit is contained in:
committed by
Caitlin Potter
parent
14e797c1a1
commit
8df5f3259a
@@ -3982,6 +3982,115 @@ describe('$compile', function() {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('nested transcludes', function() {
|
||||
|
||||
beforeEach(module(function($compileProvider) {
|
||||
|
||||
$compileProvider.directive('noop', valueFn({}));
|
||||
|
||||
$compileProvider.directive('sync', valueFn({
|
||||
template: '<div ng-transclude></div>',
|
||||
transclude: true
|
||||
}));
|
||||
|
||||
$compileProvider.directive('async', valueFn({
|
||||
templateUrl: 'async',
|
||||
transclude: true
|
||||
}));
|
||||
|
||||
$compileProvider.directive('syncSync', valueFn({
|
||||
template: '<div noop><div sync><div ng-transclude></div></div></div>',
|
||||
transclude: true
|
||||
}));
|
||||
|
||||
$compileProvider.directive('syncAsync', valueFn({
|
||||
template: '<div noop><div async><div ng-transclude></div></div></div>',
|
||||
transclude: true
|
||||
}));
|
||||
|
||||
$compileProvider.directive('asyncSync', valueFn({
|
||||
templateUrl: 'asyncSync',
|
||||
transclude: true
|
||||
}));
|
||||
|
||||
$compileProvider.directive('asyncAsync', valueFn({
|
||||
templateUrl: 'asyncAsync',
|
||||
transclude: true
|
||||
}));
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(inject(function($templateCache) {
|
||||
$templateCache.put('async', '<div ng-transclude></div>');
|
||||
$templateCache.put('asyncSync', '<div noop><div sync><div ng-transclude></div></div></div>');
|
||||
$templateCache.put('asyncAsync', '<div noop><div async><div ng-transclude></div></div></div>');
|
||||
}));
|
||||
|
||||
|
||||
it('should allow nested transclude directives with sync template containing sync template', inject(function($compile, $rootScope) {
|
||||
element = $compile('<div sync-sync>transcluded content</div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('transcluded content');
|
||||
}));
|
||||
|
||||
it('should allow nested transclude directives with sync template containing async template', inject(function($compile, $rootScope) {
|
||||
element = $compile('<div sync-async>transcluded content</div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('transcluded content');
|
||||
}));
|
||||
|
||||
it('should allow nested transclude directives with async template containing sync template', inject(function($compile, $rootScope) {
|
||||
element = $compile('<div async-sync>transcluded content</div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('transcluded content');
|
||||
}));
|
||||
|
||||
it('should allow nested transclude directives with async template containing asynch template', inject(function($compile, $rootScope) {
|
||||
element = $compile('<div async-async>transcluded content</div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('transcluded content');
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
describe('multiple siblings receiving transclusion', function() {
|
||||
|
||||
it("should only receive transclude from parent", function() {
|
||||
|
||||
module(function($compileProvider) {
|
||||
|
||||
$compileProvider.directive('myExample', valueFn({
|
||||
scope: {},
|
||||
link: function link(scope, element, attrs) {
|
||||
var foo = element[0].querySelector('.foo');
|
||||
scope.children = angular.element(foo).children().length;
|
||||
},
|
||||
template: '<div>' +
|
||||
'<div>myExample {{children}}!</div>' +
|
||||
'<div ng-if="children">has children</div>' +
|
||||
'<div class="foo" ng-transclude></div>' +
|
||||
'</div>',
|
||||
transclude: true
|
||||
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
inject(function($compile, $rootScope) {
|
||||
var element = $compile('<div my-example></div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('myExample 0!');
|
||||
dealoc(element);
|
||||
|
||||
element = $compile('<div my-example><p></p></div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.text()).toEqual('myExample 1!has children');
|
||||
dealoc(element);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user