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

Commit

Permalink
fix(ngIf): ensure that the correct (transcluded) scope is used
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin authored and vojtajina committed May 29, 2014
1 parent 19af039 commit d71df9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ng/directive/ngIf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/ng/directive/ngIfSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

1 comment on commit d71df9f

@clakech
Copy link
Contributor

@clakech clakech commented on d71df9f Nov 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cause a problem when using directive with element transclusion at the root of a replacement template #9837

There is no breaking change link to this commit and it should since this cause regression when upgrading from angular 1.2 to 1.3

This is strange to disallow element transclusion at the root of a directive and I think in this case we should use $scope.$new(); and not newScope from $transclude.

WDYT ?

Please sign in to comment.