I am making a call to a backend API which returns a JSON response. I have read a number of answers on here including this but they dont seem to cover my issue.
The JSON response from the API looks like this:
[
{
"id": "1",
"name": "test1",
},
{
"id": "2",
"name": "test2",
}
]
My Angular JS code looks like this:
controller.testDetailHolder = [];
Test.getAllTests.query({}, function(data){
for(var i=0; i<data.length;i++){
controller.testDetailHolder.name = data[i].name;
controller.testDetailHolder.id = data[i].id;
}
});
When I console.log controller.testDetailHolder it only shows the second value from the GET request (i.e. the array just holds one value) however, I want the controller.testDetailHolder to look like this:
controller.testDetailHolder = [
{
id: "1",
name: "test1",
},
{
id: "2",
name: "test2",
}
]
Any assistance with this would be greatly appreciated.
Thanks.