javascript - ng-repeat through object with value as an array angular -


i have object key value pairs looks this. see key has array value.

$scope.testobj = {     "london":[          {"id":1,"city":"london","country":"gb","name":"test1"},          {"id":4,"city":"london","country":"gb","name":"test2"}    ],     "los angeles":[        {"id":8,"city":"la","country":"us","name":"test3"}    ]  } 

i want display name next city in front end using angular. have tried many approaches, , used track $index, cannot figure out how working.

<div ng-repeat="(key, val) in jobsbycity track $index">     {{key}}:{{val[$index].name}} </div> 

i have looked @ approach too, nesting ng-repeat

 <div ng-repeat="(key, val) in testcity">     {{key}}     <div ng-repeat="test in val[$index].name">        {{test}}      </div>   </div> 

just use ng-repeat iterate on value:

<div ng-repeat="(key, val) in jobsbycity">     <div ng-repeat="subvalue in val track $index">         {{key}}:{{subvalue.name}}     </div> </div> 

also note los angeles property needs in quotes, otherwise isn't valid javascript.

see this jsfiddle


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -