Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-repeat only objects with specific property value - custom filter?

So say I have a JSON object 'user' with some basic properties like: 'name', 'address', 'role', etc.

I want the ng-repeat to only spit out the objects in which the property 'role' equates to 'administrator'. How would I go about doing that?

I'm thinking something like a custom filter, or possibly making a scope variable where I put the matching objects in an array, and then repeat through them.

What is the best practice for this case?

Thanks.

like image 493
Matt MacLeod Avatar asked Aug 19 '26 22:08

Matt MacLeod


1 Answers

The built in filter can handle this case...

<div ng-repeat="user in users | filter : {role: 'administrator'} : true">
   ...
</div>
like image 88
Anthony Chu Avatar answered Aug 21 '26 21:08

Anthony Chu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!