Skip to content

Commit b51dd30

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 angular#12528
1 parent 6e6f319 commit b51dd30

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
@@ -2628,7 +2628,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26282628
// Set up $watches for isolate scope and controller bindings. This process
26292629
// only occurs for isolate scopes and new scopes with controllerAs.
26302630
function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) {
2631-
var removeWatchCollection;
2631+
var removeWatchCollection = [];
26322632
forEach(bindings, function(definition, scopeName) {
26332633
var attrName = definition.attrName,
26342634
optional = definition.optional,
@@ -2696,7 +2696,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26962696
} else {
26972697
removeWatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal);
26982698
}
2699-
removeWatchCollection = (removeWatchCollection || []);
27002699
removeWatchCollection.push(removeWatch);
27012700
break;
27022701

@@ -2714,7 +2713,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
27142713
}
27152714
});
27162715

2717-
return removeWatchCollection && function removeWatches() {
2716+
return removeWatchCollection.length && function removeWatches() {
27182717
for (var i = 0, ii = removeWatchCollection.length; i < ii; ++i) {
27192718
removeWatchCollection[i]();
27202719
}

0 commit comments

Comments
 (0)