简体   繁体   中英

Using filter in ng-repeat

I am trying to use a filter with an expression in ng-repeat like this -

<div ng-repeat= "fruit in fruits | filter: {fruit.color !: 'red'}">
   {{ fruit }}
</div>

But it doesn't seem to work, can someone confirm that it is possible to use expression in filters(I am using angular 1.0.8)

First thing you should upgrade you Angular Version to latest, it would not make sense to stay with Angular 1.0.x

<div ng-repeat= "fruit in fruits | filter: {color : '!' + selected Color}">
   {{ fruit }}
</div>

This is just example of filter in ng-repeat:

<div ng-repeat= "fruit in fruits" >
     {{ fruit | uppercase}} 
</div>

$scope.fruits  = ['apple','banana']

OutPut:

APPLE
BANANA

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.

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