madhur madhur - 2 months ago 20
Javascript Question

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)

Answer

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 : '!red'}">
   {{ fruit }}
</div>