0

I use the ng-repeat directive to print out all posts for a user.

<div ng-repeat="post in user.posts">
  <p>{{ post.content }}</p>
</div>

I want to limit this to just printing out posts that have an "is_public" attribute equal to "true". How can I do this?

<div ng-repeat="post in user.posts ??? if post.public == true">
  <p>{{ post.content }}</p>
</div>

I've seen the use of filter with ng-repeat, but it looks like it's meant for dynamic filtering, not a case where I know what the filter should always be.

Don P
  • 60,113
  • 114
  • 300
  • 432
  • Just filter it out in the controller, use native filter. – PSL Jul 16 '15 at 01:57
  • In this situation, I need to filter it in the view. Is it possible? (The question is a simplification of what I'm actually dealing with) – Don P Jul 16 '15 at 01:59
  • Then just use angular [filter](https://docs.angularjs.org/api/ng/filter/filter). `ng-repeat="post in user.posts | filter:{public:true}"` – PSL Jul 16 '15 at 01:59
  • Possible duplicate of http://stackoverflow.com/questions/11996857/how-to-use-parameters-within-the-filter-in-angularjs , http://stackoverflow.com/questions/17793751/how-to-filter-by-object-property-in-angularjs – PSL Jul 16 '15 at 02:02

0 Answers0