Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
the right way to remove elements and splice from array
  • Loading branch information
thebigredgeek committed Aug 29, 2014
commit d36663950253d38863d8b98a012014af2c2ce903
13 changes: 5 additions & 8 deletions src/ng/directive/ngSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,15 @@ var ngSwitchDirective = ['$animate', function($animate) {

scope.$watch(watchExpr, function ngSwitchWatchAction(value) {
var i, ii;
for (i = 0, ii = previousElements.length; i < ii; ++i) {
previousElements[i].remove();
}
previousElements.length = 0;

for (i = 0, ii = selectedScopes.length; i < ii; ++i) {
var selected = getBlockNodes(selectedElements[i].clone);
selectedScopes[i].$destroy();
previousElements[i] = selected;
$animate.leave(selected).then(function() {
previousElements[i] ? previousElements.splice(i, 1) : angular.noop();
});
$animate.leave(selected).then((function(i) {
return function(){
previousElements.splice(i, 1).remove();
};
}(i));
}

selectedElements.length = 0;
Expand Down