Reputation:
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?
Upvotes: 1
Views: 43
Reputation: 13801
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}">
Upvotes: 1
Reputation: 10536
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>
Upvotes: 2