简体   繁体   English

带过滤器的AngularJS ng-repeat

[英]AngularJS ng-repeat with filter

I'm trying to use filter to exclude an item from a list using the filter:object method. 我正在尝试使用filter:使用filter:object方法从列表中排除项目。 What am I doing wrong? 我究竟做错了什么?

 <div ng-init="itemList = [
{ id: 'item1', name: 'item 1' },
{ id: 'item2', name: 'item 2' },
{ id: 'item3', name: 'item 3' } ];test='item2';">
  <ul>
    <li ng-repeat="item in itemList | filter:{ id: '!{{ test }}' }">{{ item.name }}</li>
  </ul>
</div>

Here's the Plunker 这是笨蛋

You don't need curly brackets inside angular expression. 您不需要在角度表达式内使用大括号。 Also since test is a variable, not actual value to negate you need to concatenate it with the string ! 另外,由于test是变量,因此不是要取反的实际值,您需要将其与字符串连接! to get final filter condition. 得到最终的过滤条件。

It will be: 这将是:

<li ng-repeat="item in itemList | filter:{ id: '!' + test }">{{ item.name }}</li>

Demo: http://plnkr.co/edit/vowrYe3aHLrmwmb1ounK?p=info 演示: http //plnkr.co/edit/vowrYe3aHLrmwmb1ounK?p = info

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM