Khalid Khalid - 13 days ago 6
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.

$scope.data = Object { ACCOUNT: "{"ACNO":"AC052","NAME":"madavi",…}",
CONTACTS: Array[1], RETURN: "TRUE" }


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>
<br>
</div>


How can I get values in ng-repeat?

Answer

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]);
}