1

I have a list which look like this

[
    { OfficialID:1, name:'test', isActive:false },
    { OfficialID:2, name:'test4', isActive:true },
    { OfficialID:3, name:'test2', isActive:true }
]

now I just want to filter and only show data when isAcitve is true,

and this is my tr of table

 <tr ng-repeat="d in dc.officialLeaves | filter:isActive">
     <td>{{d.OfficialID}}</td>
 </tr>

I think I know I want to use something like this filter:isActive

but what exactly should I do?

2 Answers 2

2

That is fine, but the filter will run quite often. For performance, you might consider filtering once in your component:

dc.activeOfficialLeaves = officialLeaves.filter(o => o.isActive)

 <tr ng-repeat="d in dc.activeOfficialLeaves">
     <td>{{d.OfficialID}}</td>
 </tr>
Sign up to request clarification or add additional context in comments.

Comments

1

Checkout this:https://docs.angularjs.org/api/ng/filter/filter

You can apply expression directly.

{{ filter_expression | filter : expression : comparator : anyPropertyKey}}

You can do something like this, This says only to compare with the field isActive

<tr ng-repeat="friend in friends | filter:{'isActive':true}">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.