Why is the JSON data stored in the $scope object,which was got using $http.get, is not getting printed in binding expression?

I've got the jason data from jsp and stored inside a $scope object in angularjs. The data is not printed when I tried to print inside the binding expression. However the data is shown in the console when I used console.log(response).

Below is my angular js code:

<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.js"> </script>
<script>
var myApp=angular.module("myApp",[]);
myApp.controller("myController",function($scope,$http){

    $http.get('JSON.jsp')
    .then(function(response) {

    $scope.array=response.data;
    console.log(response.data);


    });
    //This the jason data I've got:[{"NAME":"jo","AGE":20}]

});

</script>


<meta charset="ISO-8859-1">
<title>AngularCheck</title>

</head>
<body ng-controller="myController" >

{{array.NAME}} 
{{array.AGE}}



</body>
</html>

Image:The data is shown in the console.But not printed inside the binding expression

Upvotes: 0

Views: 38

Answers (1)

Maxim Shoustin
Maxim Shoustin

Reputation: 77910

From image you got array of one object.

So print it as:

{{array[0].NAME}} 
{{array[0].AGE}}

Upvotes: 2

Related Questions