AngularJS Cannot read 属性 'toLowerCase' of undefined 向数组添加项时发生

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

当运行一个向数组添加新项目的函数时:

$scope.accounts.push(responce);

(具有搜索过滤器、yes/no过滤器并排序的数组。)

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

添加新项目后,会出现此错误使用过滤器时无法读取未定义 的属性 'toLowerCase'。

注意:刷新页面后,会再次生效。

在您的函数中,将代码更改为:

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

这将防止将未定义的值添加到数组中,这应该可以修复您在使用过滤器时遇到的错误。