I'm rather confused over the difference between a factory and a service and why one would choose one over the other. Here I have a factory but is it possible to write as a service and if so what would it look like? Also what's the advantage of using a service or a factory here?
app.factory('testInterceptor', ['$q', function ($q) {
return {
'request': function (config) {
return config;
},
// optional method
'requestError': function (rejection) {
return $q.reject(rejection);
},
// optional method
'response': function (response) {
return response;
},
// optional method
'responseError': function (rejection) {
return $q.reject(rejection);
}
}
}]);
app.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push('testInterceptor');
}])