我想打印名稱的唯一值,但我無法做到這一點。AngularJS ng-repeat獨特不起作用
的html代碼:
<div ng-controller="MyCtrl">
<div><input type="text" ng-model="nameFilter" placeholder="Search..." /></div>
<p ng-repeat="contact in contacts | orderBy: 'customer.name'| unique:'customer.name'">{{ contact.customer.name }}</p>
</div>
JS代碼:
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.nameFilter = '';
$scope.contacts = [
{ id:1, customer: { name: 'foo', id: 10 } },
{ id:2, customer: { name: 'bar', id: 20 } },
{ id:3, customer: { name: 'foo', id: 10 } },
{ id:4, customer: { name: 'bar', id: 20 } },
{ id:5, customer: { name: 'baz', id: 30 } },
{ id:5, customer: { name: 'tar', id: 30 } },
{ id:5, customer: { name: 'got', id: 30 } },
{ id:5, customer: { name: 'man', id: 30 } },
{ id:5, customer: { name: 'baz', id: 30 } },
];
}
中的jsfiddle是在這裏:http://jsfiddle.net/nvarun123/0tgL7u6e/73/
此代碼工作,如果我刪除從納克重複獨特。
您的代碼缺少'unique'自定義過濾器。這不是內置的過濾器之一,所以你必須自己寫。 –
認爲獨特的過濾器已經在angularjs中定義了 – Varun
恐怕不是,[這些是內置的過濾器](https://docs.angularjs.org/api/ng/filter) –