I'm working with a REST service in my angular controller and using JSONP to make the call. I need to store the array that is returned from the service into a variable.
This is what I currently have:
this.testTheRest = function()
{
$http.jsonp('myRESTService', {
params: {
callback: 'JSON_CALLBACK',
format: 'json'
}
})
.success(function (data) {
this.testlist = data.NoParamsResult;
console.log(this.testlist);
})
.error(function (data) {
alert(data);
});
console.log(this.testlist);
}
I have already declared testlist as an empty array in the controller:
this.testlist = [];
There are two console output calls in the code. The issue I'm facing is that the first one correctly displays the array:
Array [ Object, Object ]
However, the second one shows an empty array, most likely the initialized one:
Array [ ]
What changes do I need to make in order to retain the objects returned by the service in the array?
Thank you for your assistance,
Frank