mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-09 22:39:39 +08:00
fix(ngIf): ensure that the correct (transcluded) scope is used
This commit is contained in:
committed by
Vojta Jina
parent
19af039745
commit
d71df9f83c
@@ -89,8 +89,8 @@ var ngIfDirective = ['$animate', function($animate) {
|
||||
|
||||
if (toBoolean(value)) {
|
||||
if (!childScope) {
|
||||
childScope = $scope.$new();
|
||||
$transclude(childScope, function (clone) {
|
||||
$transclude(function (clone, newScope) {
|
||||
childScope = newScope;
|
||||
clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' ');
|
||||
// Note: We only need the first/last node of the cloned nodes.
|
||||
// However, we need to keep the reference to the jqlite wrapper as it might be changed later
|
||||
|
||||
@@ -199,6 +199,25 @@ describe('ngIf and transcludes', function() {
|
||||
dealoc(element);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should use the correct transcluded scope', function() {
|
||||
module(function($compileProvider) {
|
||||
$compileProvider.directive('iso', valueFn({
|
||||
restrict: 'E',
|
||||
transclude: true,
|
||||
template: '<div ng-if="true"><div ng-transclude></div></div>',
|
||||
scope: {}
|
||||
}));
|
||||
});
|
||||
inject(function($compile, $rootScope) {
|
||||
$rootScope.val = 'transcluded content';
|
||||
var element = $compile('<iso><span ng-bind="val"></span></iso>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(trim(element.text())).toEqual('transcluded content');
|
||||
dealoc(element);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ngIf animations', function () {
|
||||
|
||||
Reference in New Issue
Block a user