fix(ngIf): ensure that the correct (transcluded) scope is used

This commit is contained in:
Peter Bacon Darwin
2014-05-23 11:45:03 +01:00
committed by Vojta Jina
parent 19af039745
commit d71df9f83c
2 changed files with 21 additions and 2 deletions

View File

@@ -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

View File

@@ -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 () {