Here is the code snippet for a service that includes a fetchData function being called from a controller.
In the Service:
app.service("geturl", function($http) {
urllist = [];
geturl.fetchData = function() {
var data = [];
for (i = 0; i < urllist.length; i++) {
(function(index) {
return $http.get(geturl.urllist[index], {
timeout: 8000
})
.then(function(response) {
data[index] = response.data;
});
}(i);
return data;
});
};
});
I need to handle the success and error functions of $http.get in the controller to be used in the UI. How should I approach this?