This is the json format:
{"data": {
"asd": {
"index": "2",
"x": "dsds",
"y": "dsadsa"
},
"sfs": {
"index": "1",
"x": "dsds",
"y": "dsds"
}
}}
I want to display these data index, x and y values using ng-repeat of angularjs. But I couldn't think of what the format will be like inside {{ }} .
I've already done some research, but most of the people recommend on changing the format. What if changing the format isn't an option? Can I still display it using ng-repeat?
What about:
<tr ng-repeat="(key, value) in dataContainer.data">
<td>{{ value.index }}</td>
<td>{{ value.x }}</td>
<td>{{ value.y }}</td>
</tr>
Working example: http://jsfiddle.net/pk7a44f7/1/
You can basically display anything in ng-repeat
if you are using the correct syntax and accessing the right values.
I've created a demo jsfiddle that displays all the items in your object.
HTML:
<div ng-app="APP" ng-controller="TST">
<div ng-repeat="(key,val) in test_obj.data">
<p>{{key}}</p>
<p ng-repeat="(k,v) in val">{{k}} - {{v}}</p>
</div>
</div>
JS:
var APP = angular.module('APP', []);
APP.controller('TST', ['$scope', function($scope) {
$scope.test_obj = {
"data": {
"asd": {
"index": "2",
"x": "dsds",
"y": "dsadsa"
},
"sfs": {
"index": "1",
"x": "dsds",
"y": "dsds"
}
}
};
}]);