本文介绍了'ng-repeat'如何获得`unique'值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用数组,我试图过滤并在列表中显示unique
信息.为此,我使用angular
inbuild filter
方法.
Using an array, I am trying to filter and show the unique
information in the list. For that I use the angular
inbuild filter
method.
但是我遇到了错误.
这是我的尝试(我正在按SubProjectName
进行过滤)
Here is my try (I am filtering by SubProjectName
)
<ul>
<li ng-repeat="project in projectNames | unique: 'SubProjectName' ">
{project.SubProjectName}}
</li>
</ul>
推荐答案
AngularJS默认不包含unique
过滤器.您可以使用 angular-filter 中的一个.只需包含JavaScript
AngularJS doesn't include a unique
filter by default. You can use the one from angular-filter. Just include the JavaScript
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.8/angular-filter.min.js"></script>
并在您的应用中添加依赖项:
and include the dependeny in your app:
var app = angular.module('myApp', ['angular.filter']);
您的代码应立即生效!我编辑了您的 Plunker ,这样就可以了.
Your code should work right away! I edited your Plunker so it works.
这篇关于'ng-repeat'如何获得`unique'值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!