Steve
Steve

Reputation: 14912

Angular JS ng-repeat filter only items with a property

I have a json file with keys like

[
 {
  "message": "Verify envelopes are properly loaded.",
  "hasFigure": false,
  "figureX": 0,
  "figureY": 0
 },
{
  "message": "Verify the paddle is in the down position.",
  "hasFigure": true,
  "figureX": 185,
  "figureY": 50
}
]

I need to put this into an ng-repeat but only show the items where hasFigure is true

I know it's a filter, but can't seem to get the syntax...

Upvotes: 2

Views: 1407

Answers (3)

Pankaj Parkar
Pankaj Parkar

Reputation: 136154

Your filter syntax would be

For safer side use strict checking by adding : true at the end of filter

<div ng-repeat="item in items | filter: {'hasFigure': true}: true"></div>

Upvotes: 3

c0deNinja
c0deNinja

Reputation: 3986

Have you tried something like this:

<div ng-repeat="stuff in stuffs | filter: { hasFigure: true }"> 

Upvotes: 0

tymeJV
tymeJV

Reputation: 104775

Why not use ng-show / ng-hide

<div ng-repeat="item in items" ng-show="item.hasFigure"></div>

Upvotes: 0

Related Questions