when I try to do an ng-repeat over an array of hashes, it appears the key becomes the index. So how can I get the key to an object like this?
[
{
"3000:501:001": {
"End Date": "05/05/2013",
"Term": "Spring Semester 2013",
"Title": "Cooperative Education",
"Career": "Graduate",
"Section": "001",
"Days": "T.B.A.",
},
{
"6200:660:801": {
"End Date": "05/05/2013",
"Term": "Spring Semester 2013",
"Career": "Graduate",
"Section": "801",
"Days": "M",
}
}
]
When I do ng-repeat="(key, course) in courses"
key is just the index 0 and 1.
I need to get "3000:501:001" and the object that key refers to. I don't know the key name.
You will need to have another ng-repeat which will iterate over the object.
But I would highly recommend having a different structure for your data if possible. You could put the colon-separated numbers as a property of the inner object.
To acheive what you are expecting you wouldn't wrap your objects in array and turn them into a single object. The reason you are getting 0,1 etc is key in an array is it's index value
JS
$scope.items={
"3000:501:001": {
"End Date": "05/05/2013",
"Term": "Spring Semester 2013",
"Title": "Cooperative Education",
"Career": "Graduate",
"Section": "001",
"Days": "T.B.A."
}
};
HTML
<li ng-repeat="(id,item) in items">{{id}}
<div ng-repeat="(key,value) in item">{{key}}: {{value}}</div>
</li>
DEMO: http://plnkr.co/edit/vyNN7HCx1t6lHD73gTLC?p=preview
In general is more convenient to use arrays for ng-repeat and restructure your data as such. It will also not require an extra ng-repeat to access the nested object