phantom phantom - 8 months ago 38
Javascript Question

ng-repeat through object with value as an array angular

I have an object with key value pairs that looks like this. You will see that the key has an array as its value.

$scope.testObj = {


"Los Angeles":[


I want to display the name next to the city in the front end using angular. To do this I have tried many approaches, and used track by $index, but cannot figure out how to get this working.

<div ng-repeat="(key, val) in jobsByCity track by $index">

I have looked at this approach too, nesting ng-repeat

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


Just use another ng-repeat to iterate over the value:

<div ng-repeat="(key, val) in jobsByCity">
    <div ng-repeat="subValue in val track by $index">

Also note that your Los Angeles property needs to be in quotes, otherwise it isn't valid javascript.

See this jsfiddle