我在类别列表中重复了成员,但我必须只显示带有ng-repeat的非重复成员。如何过滤此列表以仅显示非重复成员我有代码示例。
请参阅下面的视图
<tr ng-repeat="category in cc.categoriesList "
ng-click="cc.selectCatForNewTask(category.cid)"
ng-class="{selected: cc.getCtgRowClass(category.cid)}">
<td>
{{category.categoryName}}
</td>
</tr>
答案 0 :(得分:1)
试试这个:
<tr ng-repeat="category in cc.categoriesList | unique:category.somefield " ng-click="cc.selectCatForNewTask(category.cid)" ng-class="{selected: cc.getCtgRowClass(category.cid)}">
<td> {{category.categoryName}} </td>
</tr>
您需要安装一些依赖项:
1。在您的终端中,转到您的项目并运行以安装angular-ui-utils unique:
bower install angular-ui-utils#bower-unique
2。要求将unique.js文件添加到角度脚本下方的项目中:
<!-- angular script -->
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<!-- unique script -->
<script type="text/javascript" src="bower_components/angular-ui-utils/unique.js"></script>
3. 将独特的模块添加到您的应用中:
angular.module('myApp', ['ui.unique'])
此处提供的源代码:AngularUI unique filter