ngSwitch regression 1.2.14 and up - crash in ng-switch with multiple ng-switch-when using the same term. #7372
Description
Hi!
After upgrading to angular 1.2.16, we noticed a regression in the ngSwitch directive that seems to have been present since 1.2.14 and is also still present in 1.3.0 beta-7.
The issue occurs when two elements have the same ng-switch-when value. When toggling between values of the switch expression, angular will throw the following error when it tries to "hide" the elements having the same ng-switch-when.
The call stack produced by the error:
TypeError: Cannot read property 'remove' of undefined
at Object.ngSwitchWatchAction [as fn] (https://code.angularjs.org/1.2.14/angular.js:20225:34)
at Scope.$digest (https://code.angularjs.org/1.2.14/angular.js:11930:29)
at Scope.$apply (https://code.angularjs.org/1.2.14/angular.js:12179:24)
at HTMLAnchorElement.<anonymous> (https://code.angularjs.org/1.2.14/angular.js:18228:21)
at https://code.angularjs.org/1.2.14/angular.js:2673:10
at forEach (https://code.angularjs.org/1.2.14/angular.js:329:20)
at HTMLAnchorElement.eventHandler (https://code.angularjs.org/1.2.14/angular.js:2672:5) angular.js:9509
(anonymous function) angular.js:9509
(anonymous function) angular.js:6950
Scope.$digest angular.js:11949
Scope.$apply angular.js:12179
(anonymous function) angular.js:18228
(anonymous function) angular.js:2673
forEach angular.js:329
eventHandler angular.js:2672
Reproduction:
Here is a js fiddle that reproduces this issue: http://jsfiddle.net/QZkZN/4/
(Click on "show edit", then "cancel", then "show edit" again to trigger the error.)
Reproducibility:
The bug is 100% reproductible on chrome latest - we haven't tried other browsers.
Source of the regression:
This line and the surrounding code introduced in commit e988199 (changes to file: src/ng/directive/ngSwitch.js
) is causing the error:
angular.js/src/ng/directive/ngSwitch.js
Line 149 in e988199