Following the tutorial on docs.angularjs.org, step 2. How do I update this array to a nested one?
This is the basic array:
'use strict';
/* Controllers */
function PhoneListCtrl($scope){
$scope.phones = [
{"name" : "Samsung Galaxy S4",
"snippet" : "Operativsystem : Android 4.2.2"
}
]
}
This illustrates what i want to do:
'use strict';
/* Controllers */
function PhoneListCtrl($scope){
$scope.phones = [
{"name" : "Samsung Galaxy S4",
"snippet" : {"Operativsystem" : "Android 4.2.2",
"Skärm" : "4,99 tum",
"CPU" : "Quad-core",
"Kamera, bak" : "13 MP",
"Kamera, fram" : "1,9 MP",
"Övrigt" : "Närfältskommunikation (Eng. near field communication, NFC)"
}
}
]
}
My current HTML template:
<body ng-controller ="PhoneListCtrl">
<h1>The future of mobile devices</h1>
<ul>
<li ng-repeat="phone in phones">
<h3>{{phone.name}}</h3>
<p>{{phone.snippet}}</p>
</li>
</ul>
<p>Total number of phones: 2</p>
</body>
I see that i can use {{phone.snippet.Operativsystem}} to get the first element. But I also want the label Operativsystem to be printed in the HTML, like so:
- Operativsystem: Android 4.2.2
- Skärm: 4,99 tum
- CPU: Quad-core
- Kamera, bak: 13 MP Kamera, fram: 1,9 MP
- Övrigt: Närfältskommunikation (Eng.near field communication, NFC)
I realize I can just do like below, but that still does not print the "attribute names/keys" in the HTML only the values
<ul>
<li ng-repeat="phone in phones">
<h3>{{phone.name}}</h3>
<ul>
<li ng-repeat="key in phone.snippet">
{{key}}
</li>
</ul>
<p>{{phone.snippet}}</p>
</li>
</ul>