Reputation: 467
Return json form the API which is
{ ACC: "{"NO":"AC307","NAME":"joe"}, RETURN: "TRUE" }
i need the value separate as NO, NAME , ... how can i
HTML:
<div ng-repeat="acdetails in accdetails ">
<div class="item item-divider item-input-wrapper">
Acc No - {{ acetails.NO }}
</div>
<div class="item item-divider item-input-wrapper">
Name - {{ acdetails.NAME }}
</div>
</div>
but its displaying as empty , i am new to angular help me out
Thank you in advance
Upvotes: 0
Views: 464
Reputation: 467
I found the solution for this
Actual RETURN DATA:
{ ACC: "{"NO":"AC307","NAME":"joe"}, RETURN: "TRUE" }
just in your controller use json parse
.success(function(data) {
if(data.RETURN == "TRUE") {
var acdetailsObject = JSON.parse(data.ACC);
$scope.acdetails = acdetailsObject;
}
your data will be as format below
{ NO: "AC00316", NAME: "John Doe" }
then in your html you can directly fetch using $scope.acdetails with out using any ng-repeat , as below
<div class="item item-divider item-input-wrapper">
Acc No - {{ acdetails.NO }}
</div>
<div class="item item-divider item-input-wrapper">
Name - {{ acdetails.NAME }}
</div>
</div>
Upvotes: 0
Reputation: 1695
The JSON is invalid. Assuming that in your angular controller you have the following (note that this is an array of objects)
$scope.accdetails = [{
"ACC": {
"NO":"AC307",
"NAME":"joe",
},
"RETURN": "TRUE"
}];
then the following html displays the desired information
<div ng-repeat="acdetails in accdetails">
<div class="item item-divider item-input-wrapper">
Acc No - {{ acdetails.ACC.NO }}
</div>
<div class="item item-divider item-input-wrapper">
Name - {{ acdetails.ACC.NAME }}
</div>
</div>
Upvotes: 1
Reputation: 2244
You JSON is not valid. Valid json below
{"ACC": {
"NO": "AC307",
"NAME": "joe",
"ST": "",
"RETURN": "TRUE"
} }
Upvotes: 0
Reputation: 2280
try Changing Acc No - {{ acetails.NO }}
to Acc No - {{ acetails.ACC.NO }}
Upvotes: 0