Michael Letcher Michael Letcher - 1 year ago 62
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download