angularjs - Could I write a HttpInterceptor as a service? -
i'm rather confused on difference between factory , service , why 1 choose 1 on other. here have factory possible write service , if like? what's advantage of using service or 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'); }])
Comments
Post a Comment