我是angularJS的新手但是这个错误让我发疯了。
我有一个搜索过滤器,可以在其过滤的元素中显示匹配的术语。
控制器中的搜索功能如下所示:
$scope.search = ''; //This is the search query
$scope.matches = new Array(); //This holds the matching terms for all the elements
$scope.filterBySearch = function(el) {
$scope.matches[el.artist_id] = '';
var regex = new RegExp($scope.search, 'i');
if (!$scope.search) return true;
var res = multisearch.test(el,regex); //This search function returns an array containing all the matching terms
$scope.matches[el.artist_id] = res;
return (res.length>0);
};
在HTML中我有:
<p>
<input type="text" class="form-control" ng-model="search" placeholder="Search...">
</p>
<div>
<ul ng-model="artists">
<li data-id="[~artist.artist_id~]" ng-repeat="artist in artists | filter:filterBySearch">
<div class="title">[~artist.title~]</div>
<div class="matches-container">
<div class="match" ng-repeat="match in matches[artist.artist_id]">match</div>
</div>
</li>
</ul>
</div>
过滤功能有效,匹配的术语也出现了,但我收到了这个错误:
Error: [$rootScope:infdig]
我相信这意味着角度陷入无限循环并退出。 艾米关于可能导致这个问题的想法?