ngSwitchWhen is throwing error 'Cannot read property 'NaN' of undefined'
I am overwriting existing filter method on Array prototype, this works with angular 1.5.7 version.
Recently I upgraded it to 1.6.10. Same code is not working and throwing error Cannot read property 'NaN' of undefined in browser console.
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>
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];
I have reproduced this issue in plunker.
Your monkey patch of
Array.prototype.filteris defective:The callback should be invoked with three arguments:
Update
The ES5 Standard recommends this polyfill:
For more information, see MDN JavaScript Reference - Array.prototype.filter polyfill.