Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have retrieved json data using angular factory.When I alert the data it displays undefined.My json is:
[{"chqNoId":5,"chqNo":5,"custName":"Bikash Paneru","status":"cancelled"}]

I want to alert status only when I alert using :
alert($scope.Cheque); It displays [object Object]
            alert($scope.Cheque.status); It displays undefined
.

How to alert status?

What I have tried:

$scope.ChqStatus = function(chqno)
   {
       crudServiceUser.GetChqStatus(chqno).then(function (result) {
           $scope.Cheque = result;
           alert($scope.Cheque);
           alert($scope.Cheque.status));
       })

   }
Posted
Updated 22-Apr-17 3:33am
Comments
F-ES Sitecore 22-Apr-17 10:15am    
Square brackets indicate an array of objects rather than a single object. Your json could also be like this

[{"chqNoId":5,"chqNo":5,"custName":"Bikash Paneru","status":"cancelled"}, {"chqNoId":6,"chqNo":6,"custName":"John Doe","status":"authorised"}]

That would be two objects in the array but your json only has one item in the array so you access it via Cheque[0] as suggested in Solution 1

1 solution

try
alert($scope.Cheque[0].status)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900