I
I
Ilya2014-12-23 23:47:23
Angular
Ilya, 2014-12-23 23:47:23

How to process json in angularJS?

I make a request in angularJS to the API:

$http.get('').
    success(function(data, status, headers, config) {
      $scope.dialogs = data;
    }).
    error(function(data, status, headers, config) {
      // log error
    });

It returns like this:
{
"status": "success",
"response": [
{
"id": "32",
"id_user": "31",
"id_contact": "32",
"name": "admin2",
"login": "admin2",
"email": "[email protected]",
"hash": "$2y$11$2a7b86bb9cf7d08b92fa0uVmJM1lw\/EVo.1w3Oqlg8.Sb9gDbKsYW",
"key": "$2y$11$9938ba8be955f8cb1f3b4u0\/CL5AeVY88bqd7Dla03hkdUGHP6GYu",
"date_reg": "2014-12-16",
"approved": "1"
}
]
}

How do I now refer to the objects of the returned json in the display?
With angularJS, in fact, as in js, to you and with respect.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2014-12-24
@FireGM

Apparently you have a number of users in response.
This code will display some fields on the page.

<div ng-repeat="user in dialogs.response">
    <p>{{ name }}</p>
    <p>{{ login }}</p>
    <p>{{ data_reg }}</p>
</div>

inside the controller where http.get/$scope.dialogs is defined.

H
haiku, 2014-12-24
@haiku

angular.fromJson(data) or what is the problem?
JSON is just a string, what and why are you going to access it? At least it must first be deserialized into an object and the view must already be attached to it.
well, in the dialogs, you probably still need to throw not data, but data.response .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question