Khalid Khalid - 1 year ago 78
AngularJS Question

How to Fetch data when the array is inside Json object in angularjs?

I have a API response DATA which is like below, there I'm trying to extract CONTACTS which I needed.

$ = Object { ACCOUNT: "{"ACNO":"AC052","NAME":"madavi",…}",

After Extracting the CONTACTS from the json and i get

Array [ "{"CONTACTNAME":"Mr. sdhar","CONTA…"}",
"{"CONTACTNAME":"Ms. uma","CONTACTPH…"}" ]

I'm trying like this

$scope.contactdetails = data.CONTACTS;

<div ng-repeat="contacts in contactdetails">
<a> {{ contact.CONTACTNAME }} </a>
<a> {{ contact.CONTACTEMAIL }} </a>
<a> {{ contact.CONTACTPHONE }} </a>

How can I get values in ng-repeat?

Answer Source

Each element in your array seems to be in string form, so after assigning it run JSON.parse on it:

$scope.contactdetails   = data.CONTACTS; 

for(var x = 0; x < $scope.contactdetails.length; x++){
    $scope.contactdetails[x] = JSON.parse($scope.contactdetails[x]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download