Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d71df9f

Browse files
petebacondarwinvojtajina
authored andcommitted
fix(ngIf): ensure that the correct (transcluded) scope is used
1 parent 19af039 commit d71df9f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/ng/directive/ngIf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ var ngIfDirective = ['$animate', function($animate) {
8989

9090
if (toBoolean(value)) {
9191
if (!childScope) {
92-
childScope = $scope.$new();
93-
$transclude(childScope, function (clone) {
92+
$transclude(function (clone, newScope) {
93+
childScope = newScope;
9494
clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' ');
9595
// Note: We only need the first/last node of the cloned nodes.
9696
// However, we need to keep the reference to the jqlite wrapper as it might be changed later

test/ng/directive/ngIfSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,25 @@ describe('ngIf and transcludes', function() {
199199
dealoc(element);
200200
});
201201
});
202+
203+
204+
it('should use the correct transcluded scope', function() {
205+
module(function($compileProvider) {
206+
$compileProvider.directive('iso', valueFn({
207+
restrict: 'E',
208+
transclude: true,
209+
template: '<div ng-if="true"><div ng-transclude></div></div>',
210+
scope: {}
211+
}));
212+
});
213+
inject(function($compile, $rootScope) {
214+
$rootScope.val = 'transcluded content';
215+
var element = $compile('<iso><span ng-bind="val"></span></iso>')($rootScope);
216+
$rootScope.$digest();
217+
expect(trim(element.text())).toEqual('transcluded content');
218+
dealoc(element);
219+
});
220+
});
202221
});
203222

204223
describe('ngIf animations', function () {

0 commit comments

Comments
 (0)