0

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');
}])
  • http://stackoverflow.com/questions/13762228/confused-about-service-vs-factory – Jason S Feb 26 '16 at 00:08
  • Possible duplicate of [What is the type friendly injection?](http://stackoverflow.com/questions/25667321/what-is-the-type-friendly-injection) – Paul Sweatte Aug 29 '16 at 19:02

0 Answers0