Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

Iam newbie in angularjs.How to display the json in html using angularjs.Below is the code

var app = angular.module('myapp', []);
app.controller('myctrl', function($scope, $http) {
    $http.get("http://localhost:8080/xyz").then(function (response) {

    });
});

Reponse is :

[
  {
    "city": "animal"
  },
  {
    "city": "bird"
  }
]
share|improve this question

In your controller you should assign your json to a scope:

app.controller('myctrl', function($scope, $http) {
    $scope.myArray = [];
    $http.get("http://localhost:8080/xyz").then(function (response) {
        $scope.myArray = response;
    });
});

Then in your view, you can do something like:

<div ng-controller="myctrl">
    <ul ng-repeat="obj in myArray">
        <li>{{obj.city}}</li>
    </ul>
</div>
share|improve this answer
    
i had already tried like this ,but the page is blank – Teja Jun 21 '16 at 10:55

use ng-repeat like this.

<div ng-repeat="t in test">
  <span>{{t.city}}</span>
</div>

plunker here

share|improve this answer
    
In Plunker its displaying,but in my page its not displaying.I checked the JSON link twice its giving the reponse.But data is not displaying – Teja Jun 21 '16 at 11:22
    
share your code. with html and js – Durgpal Singh Jun 21 '16 at 11:34
    
edit your question where i can see your code. – Durgpal Singh Jun 21 '16 at 11:43

Use the following code this might help you.

myArray = JSON.parse(response);

for ( var index in myArray ) {

var singleObject = myArray[index];
var keys = Object.keys[singleObject];
      for ( var j in keys ) {
            console.log("Value of key"+j+"is"+keys[j]+"in Object"+index);
      }
}

Here response is a string value.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.