独特的不在angular.js工作

时间:2015-04-14 05:29:13

标签: javascript angularjs unique

这是我的代码

<ul>
  <li ng-repeat="x in names | orderBy:'-name' | unique: 'name'">
    {{ ' Name =  ' + (x.name | uppercase) + ' &nbsp; &nbsp; Roll No = ' + x.rollno }}
  </li>
</ul>
<script>
angular.module('myApp', []).controller('namesCtrl', function($scope) {
    $scope.names = [
        {name:'aaaaaa',rollno:'1'},
        {name:'aabbbb',rollno:'2'},
        {name:'aabbcc',rollno:'3'},
        {name:'ddeegg',rollno:'4'},
        {name:'ddeegg',rollno:'4'},
    ];
});
</script>

它会显示结果

  • 名称= DDEEGG | Roll No = 4

  • 名称= DDEEGG | Roll No = 4

  • 名称= AABBCC | Roll No = 3

  • 名称= AABBBB | Roll No = 2

  • 名称= AAAAAA | Roll No = 1

但我希望结果没有重复的条目,如

  • 名称= DDEEGG | Roll No = 4

  • 名称= AABBCC | Roll No = 3

  • 名称= AABBBB | Roll No = 2

  • 名称= AAAAAA | Roll No = 1

1 个答案:

答案 0 :(得分:1)

包含angular.ui.filter.js,然后在您的应用中加入ui.filters模块

var app = angular.module('app', ['ui.filters']);

然后使用

  <ul>
    <li ng-repeat="x in names | orderBy:'-name' | unique: 'name'">
      {{ ' Name = ' + (x.name | uppercase) + ' &nbsp; &nbsp; Roll No = ' + x.rollno }}
    </li>
  </ul>

Working Plunkr这里