I want to display json object in the view. The code is:
<ul ng-repeat="item in items">
<li ng-repeat="(key, val) in item">
{{key}}: {{val}}
</li>
</ul>
In, the controller :
$scope.init = function (){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
$scope.items = JSON.parse(xhr.responseText);
console.log(JSON.parse(xhr.responseText));
}
};
xhr.open('GET', 'http://127.0.0.1:8000/user_list/', true);
xhr.send(null);
}
After console.log I'm getting
[{"user_name": "Pranav", "user_id": 1}, {"user_name": "Sagar", "user_id": 2}]
which I'm not able to manipulate like in previous example.
How to convert it in the format :
$scope.items =
[
{"user_name": "Pranav", "user_id": 1},
{"user_name": "Sagar", "user_id": 2}]
];
So, I can use it.