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

Commit f08a0c5

Browse files
refactor($compile): initialize removeWatchCollection at the start
This check means that we don't have to keep checking whether the collection has been created when adding a new watcher Closes #12528
1 parent 6f1e0ba commit f08a0c5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/ng/compile.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -2574,7 +2574,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
25742574
// Set up $watches for isolate scope and controller bindings. This process
25752575
// only occurs for isolate scopes and new scopes with controllerAs.
25762576
function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) {
2577-
var removeWatchCollection;
2577+
var removeWatchCollection = [];
25782578
forEach(bindings, function(definition, scopeName) {
25792579
var attrName = definition.attrName,
25802580
optional = definition.optional,
@@ -2642,7 +2642,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26422642
} else {
26432643
removeWatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal);
26442644
}
2645-
removeWatchCollection = (removeWatchCollection || []);
26462645
removeWatchCollection.push(removeWatch);
26472646
break;
26482647

@@ -2660,7 +2659,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26602659
}
26612660
});
26622661

2663-
return removeWatchCollection && function removeWatches() {
2662+
return removeWatchCollection.length && function removeWatches() {
26642663
for (var i = 0, ii = removeWatchCollection.length; i < ii; ++i) {
26652664
removeWatchCollection[i]();
26662665
}

0 commit comments

Comments
 (0)