我试图在指令模板中过滤ng-repeat的结果。以下解决方案的工作原理在屏幕上显示得很好,但我现在收到错误:Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
我引用了此页面并且解决方案无效:https://docs.angularjs.org/error/ $ rootScope / infdig
有关如何解决此问题的任何建议?还是一个更好的方式来解决它?
HTML:
<filtered-set items="businesses | filter : {cat: 'jedi'} : true | filter:query |orderBy: orderList"></filtered-set>
模板:
<div class="bscroll mThumbnailScroller" data-mts-axis="x">
<ul>
<li class="business-card" data-ng-repeat="business in items" data-ng-click="select(business)">
<h2>{{business.name}}</h2>
<p>{{business.cat}}</p>
</li>
</ul>
</div>
Angular JS:
.controller('starWarsCtrl', function ($scope) {
$scope.businesses = [
{"name": "Obi-Wan Kenobi",
"index":88,
"cat": "jedi"},
{"name": "Yoda",
"index":69,
"cat":"jedi"},
{"name": "Lando",
"index":31,
"cat": "smuggler"},
{"name": "Han Solo",
"index":90,
"cat": "smuggler"},
{"name": "Darth Vader",
"index":98,
"cat": "sith"},
{"name": "Jar-Jar Binks",
"index":80,
"cat": "alien"},
{"name": "Mace Windu",
"index":45,
"cat": "jedi"},
{"name": "Chewy",
"index":76,
"cat": "smuggler"}
];
.directive('filteredSet', function() {
return {
restrict: 'E',
scope: {
items: '='
},
templateUrl: 'partials/filtered-set.html'
};
});
答案 0 :(得分:0)
可能有办法解决我的上述问题,但是我找到了一个更好的解决方案来避免这个问题。这是我做的事情:
我在我的控制器中创建了这个函数,它基本上抓住了与SET lc_messages to 'en_US.UTF-8';
属性匹配的所有JSON属性:
"cat"
和我的HTML,基本上是 angular.forEach($scope.data, function(item) {
//item.cat is a string
if (categories.indexOf(item.cat) == -1) {
categories.push(item.cat);
}
});
return categories;
}
中的ng-repeat
:
ng-repeat
我还使用我的解决方案创建了一个Codepen:http://codepen.io/Auzy/pen/adeqrP
我希望这有帮助!