Michael Letcher Michael Letcher - 2 months ago 5x
AngularJS Question

AngularJS Cannot read property 'toLowerCase' of undefined occurs when adding an item to an array

When running a function that adds a new item to an array:


(the array that has a search filter, yes/no filter and is ordered.)

ng-repeat="x in accounts | searchFilter:searchString | enabledFilter:isEnabled | orderBy: ['-favourite','account'] as results"

Once a new item is added, this error occurs Cannot read property 'toLowerCase' of undefined when using the filters.

Note: After a refresh of the page, it will work again.


In your function, change the code to this:

if (responce !== undefined) $scope.accounts.push(responce);

This will prevent undefined values from being added to the array which should fix the error you were getting with the filter.