DiPix DiPix - 6 months ago 16
AngularJS Question

ng-repeat inside document with specific ID

I've a document with array inside eg.:

$scope.items = [
{
"id": 1,
"name": "Apple"
"types": [{
"color": "red"
"size": "xxl
},
{
"color: "green"
"size": "S"
}]
},
{
...
}]


And i'd like to display all records from
Array "types"
only for items ID = 1.

I tried this (doesn't work):

table(style="width:100%")
tr(ng-repeat="type in items.types" ng-if="items.id==1")
td
p {{ type.color}}
td
p {{ type.size}}

Answer

This can be easily implement by having two ng-repeat with filter, which will filter out the items which has id 1, and do ng-repeat on that types collection.

table(style="width:100%")
   tbody(ng-repeat="item in items | filter: {id: 1 }: true")
     tr(ng-repeat="type in items.types")
          td
              p {{ type.color}}
          td
              p {{ type.size}}