I'm trying to use filter to exclude an item from a list using the filter:object method. 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 !
to get final filter condition.
It will be:
<li ng-repeat="item in itemList | filter:{ id: '!' + test }">{{ item.name }}</li>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.