From 712299c2a24390e74cd5c20f51cb1d78f0233b6f Mon Sep 17 00:00:00 2001 From: The Big Red Geek Date: Thu, 4 Sep 2014 12:41:47 +0100 Subject: [PATCH 1/2] fix(ngSwitch): ensure correct iterator is passed to async function Closes #8833 --- src/ng/directive/ngSwitch.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index f5d824a881dc..3a7377f0574e 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -154,11 +154,12 @@ var ngSwitchDirective = ['$animate', function($animate) { for (i = 0, ii = selectedScopes.length; i < ii; ++i) { var selected = getBlockNodes(selectedElements[i].clone); selectedScopes[i].$destroy(); - var promise = previousLeaveAnimations[i] = $animate.leave(selected); - promise.then(function() { - previousLeaveAnimations.splice(i, 1); - }); + promise.then((function(i) { + return function(){ + previousLeaveAnimations.splice(i, 1); + }; + }(i))); } selectedElements.length = 0; From 24c1d73c7bcad15207efae923993c81acf722dd1 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 4 Sep 2014 13:00:05 +0100 Subject: [PATCH 2/2] refact(ngSwitch): don't create extra function in for loop --- src/ng/directive/ngSwitch.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index 3a7377f0574e..4c11f62f0421 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -144,6 +144,10 @@ var ngSwitchDirective = ['$animate', function($animate) { previousLeaveAnimations = [], selectedScopes = []; + var spliceFactory = function(array, index) { + return function() { array.splice(index, 1); }; + }; + scope.$watch(watchExpr, function ngSwitchWatchAction(value) { var i, ii; for (i = 0, ii = previousLeaveAnimations.length; i < ii; ++i) { @@ -155,11 +159,7 @@ var ngSwitchDirective = ['$animate', function($animate) { var selected = getBlockNodes(selectedElements[i].clone); selectedScopes[i].$destroy(); var promise = previousLeaveAnimations[i] = $animate.leave(selected); - promise.then((function(i) { - return function(){ - previousLeaveAnimations.splice(i, 1); - }; - }(i))); + promise.then(spliceFactory(previousLeaveAnimations, i)); } selectedElements.length = 0;