独特的不angular.js工作 [英] Unique not working in angular.js

查看:119
本文介绍了独特的不angular.js工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code

<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 |辊否= 4

  • Name = DDEEGG | Roll No = 4

名称= DDEEGG |辊否= 4

Name = DDEEGG | Roll No = 4

名称= AABBCC |卷否= 3

Name = AABBCC | Roll No = 3

名称= AABBBB |辊否= 2

Name = AABBBB | Roll No = 2

名称= AAAAAA |辊否= 1

Name = AAAAAA | Roll No = 1

但是,我要像没有重复的条目结果


  • 名称= DDEEGG |辊否= 4

  • Name = DDEEGG | Roll No = 4

名称= AABBCC |卷否= 3

Name = AABBCC | Roll No = 3

名称= AABBBB |辊否= 2

Name = AABBBB | Roll No = 2

名称= AAAAAA |辊否= 1

Name = AAAAAA | Roll No = 1

推荐答案

包含然后angular.ui.filter.js包括 ui.filters 模块中您的应用程序

Include angular.ui.filter.js then include ui.filters module in your app

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>

工作Plunkr 这里

这篇关于独特的不angular.js工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆