created factory 'resinterceptor' , in using functions(requestinterceptor,responseinterceptor) defined outside of factory. , giving error '$q not defined' inside function. want way only. please suggest how access $q inside requestinterceptor , responseinterceptor.
angular.module('resmodule', ['ngresource', 'ngcookies']) .factory('resinterceptor', ['$rootscope', '$q', '$location', resinterceptor]); function resinterceptor($rootscope, $q, $location) { return { request: requestinterceptor, response: responseinterceptor, }; } function requestinterceptor(config) { return config || $q.when(config); //$q not defined } function responseinterceptor(response) { return response || $q.when(response); }
in order work, need pass $q
along explicitly , make requestinterceptor
return actual callback function:
function resinterceptor($rootscope, $q, $location) { return { request: requestinterceptor($q), .. }; } function requestinterceptor($q) { return function (config) { return config || $q.when(config); }; }
of course, less complicated if inlined functions same scope $q
defined in first place.
Comments
Post a Comment