Suppose I have the following controller:
test.controller
App.controller('TestController', ['$scope', '$http', '$resource' , 'InitService', function($scope, $http, $resource, InitService) {
$scope.createProduct = function(product) {
InitService.createProduct(product).then(
function(d) {
$scope.product = d;
}
);
}
$scope.createProduct2 = function(product2) {
InitService.createProduct2(product2).then(
function(d) {
$scope.product = d;
}
);
}
and the test.service service
App.factory('InitService', ['$http','$q',function($http, $q) {
var REST_SERVICE_URI = 'http://localhost:8090/test/databases';
return {
createProduct : function(product) {
return $http({
method: 'POST',
url: REST_SERVICE_URI + "/product1",
data: product,
}).then(function success(response) {
return response.data;
}, function error(response) {
});
},
createProduct2 : function(product) {
return $http({
method: 'POST',
url: REST_SERVICE_URI + "/product2",
data: product,
}).then(function success(response) {
return response.data;
}, function error(response) {
});
},
How could it be done so that each rest call leaves a loading ?, I had thought about a $ scope.showLoading, but to put it in each method would not be elegant, some other suggestion?
Thanks