ngSwitchWhen Issue: Error Message 'Cannot read property 'NaN' of undefined'
After successfully implementing a filter method on the Array prototype with Angular 1.5.7, I faced an issue when upgrading to version 1.6.10. The same code that used to work is now throwing an error message
'Cannot read property 'NaN' of undefined'
in the browser console.
Snippet from HTML:
<select ng-model="selection" ng-options="item for item in items">
</select>
<code>selection={{selection}}</code>
<hr/>
<div class="animate-switch-container"
ng-switch on="selection">
<div class="animate-switch" ng-switch-when="settings|options" ng-switch-when-separator="|">Settings Div</div>
<div class="animate-switch" ng-switch-when="home">Home Span</div>
<div class="animate-switch" ng-switch-default>default</div>
</div>
Snippet from Controller:
Array.prototype.filter = function (predicateFunction) {
let results = [];
this.forEach((item) => {
if (predicateFunction(item)) {
results.push(item);
}
});
return results;
};
$scope.items = ['settings', 'home', 'options', 'other'];
$scope.selection = $scope.items[0];
To reproduce this issue, you can view the example on Plunker.