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

Commit 3949438

Browse files
committed
fix(ngIf): don't create multiple elements when changing from a truthy…
… to another thruthy value. (another way of fixing it) Fixes #4852.
1 parent 4612705 commit 3949438

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/ng/directive/ngIf.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
</file>
8080
</example>
8181
*/
82-
var ngIfDirective = ['$animate', function($animate) {
82+
var ngIfDirective = ['$animate', '$parse', function($animate, $parse) {
8383
return {
8484
transclude: 'element',
8585
priority: 600,
@@ -89,10 +89,12 @@ var ngIfDirective = ['$animate', function($animate) {
8989
compile: function (element, attr, transclude) {
9090
return function ($scope, $element, $attr) {
9191
var block, childScope;
92-
$scope.$watch($attr.ngIf, function ngIfWatchAction(value) {
93-
94-
if (toBoolean(value)) {
95-
if (!childScope) {
92+
$scope.$watch(
93+
function ngIfWatchExpression() {
94+
return toBoolean($parse($attr.ngIf)($scope));
95+
},
96+
function ngIfWatchAction(value) {
97+
if (value) {
9698
childScope = $scope.$new();
9799
transclude(childScope, function (clone) {
98100
block = {
@@ -101,20 +103,19 @@ var ngIfDirective = ['$animate', function($animate) {
101103
};
102104
$animate.enter(clone, $element.parent(), $element);
103105
});
104-
}
105-
} else {
106-
107-
if (childScope) {
108-
childScope.$destroy();
109-
childScope = null;
110-
}
111-
112-
if (block) {
113-
$animate.leave(getBlockElements(block));
114-
block = null;
106+
} else {
107+
if (childScope) {
108+
childScope.$destroy();
109+
childScope = null;
110+
}
111+
112+
if (block) {
113+
$animate.leave(getBlockElements(block));
114+
block = null;
115+
}
115116
}
116117
}
117-
});
118+
);
118119
};
119120
}
120121
};

0 commit comments

Comments
 (0)