user7052596
user7052596

Reputation:

Getting "undefined" value in $http angularjs

I am trying to get values from json in Angularjs 1.5.But i am getting "undefined"

function getData() {
  $http.get("processRequest.jsp?requestType=getRecords&page=1& limit=20").then(function(response) {
    $scope.totalItems = response.data.ordersCount
    alert(response.data.ordersCount)
  }); 

JSON values

 [{"ordersCount":"100"},{"records":{"MON_FE_ACCNO":"100001810035","MON_FE_CUSTID":"1007","MON_FE_CUSTNAME":"RajKumar","MON_FE_EXEEDING_AMT":"180000"}}]

EDITED:

If i will use $scope.totalItems = response.data[0].ordersCount working fine.why i can't get $scope.totalItems = response.data.ordersCount

Please suggested to me, Where is my mistake?

Upvotes: 1

Views: 102

Answers (1)

Sachila Ranawaka
Sachila Ranawaka

Reputation: 41387

since this is an array you need to access 0th position

 $scope.totalItems = response.data[0].ordersCount

Upvotes: 1

Related Questions