This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Transclude issue #7530
Closed
Closed
Transclude issue #7530
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1497,6 +1497,114 @@ 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('transclude and children', function() { | ||
beforeEach(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 | ||
|
||
})); | ||
|
||
})); | ||
|
||
it("should not pick up too many children when transcluding", inject(function($compile, $rootScope) { | ||
var element = $compile('<div my-example></div>')($rootScope); | ||
$rootScope.$digest(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vojtajina This is not needed now I've rewritten the ngif fix. I'll close this and send in a series of prs for all this today |
||
$rootScope.$digest(); | ||
expect(element.text()).toEqual('myExample 0!'); | ||
dealoc(element); | ||
|
||
element = $compile('<div my-example><p></p></div>')($rootScope); | ||
$rootScope.$digest(); | ||
$rootScope.$digest(); | ||
expect(element.text()).toEqual('myExample 1!has children'); | ||
dealoc(element); | ||
})); | ||
|
||
}); | ||
|
||
|
||
|
||
it("should fail if replacing and template doesn't have a single root element", function() { | ||
module(function($exceptionHandlerProvider) { | ||
$exceptionHandlerProvider.mode('log'); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a small nit, because I had trouble coming up with a good name for this failing test case when I was looking at this on Tuesday, too, but I feel like this description makes it hard to understand what the actual expected behaviour is. "should not..." and "too many..." feel wrong here.
Again, I'm not sure what a good name for this would be, so maybe this is okay, it just doesn't seem to send the right signals, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll rename