javascript - Can I inject provider into factory? -


i want create httprequestinterceptor use in .config of application.

$httpprovider.interceptors.push('httprequestinterceptor'); 

i have provider , factory of requestinterceptor:

angular.module('app.services', []) .provider('appprovider', [function () {     var apiurl = "http://url/api";     var _authtoken = null;     var _currentuser = null;      this.$get = function($q, $http, $cookiestore) {         var service = {             getauthtoken: function() {                 return _authtoken ?                      $cookiestore.get('authtoken') ?                          (_authtoken = $cookiestore.get('authtoken'), _authtoken) :                         '' : _authtoken;             }         };            return service     } }]) .factory('httprequestinterceptor', [function () {     return {         request: function(config) {             config.headers = {'auth-toke': appprovider.getauthtoken()}             return config;         }     }; }]); 

i error: cannot read property 'getauthtoken' of undefined

how fix issue?

inject appprovider:

.factory('httprequestinterceptor', ['appprovider', function (appprovider) {      return {         request: function(config) {             config.headers = {'auth-toke': appprovider.getauthtoken()}             return config;         }     }; }]); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -