javascript - Angular Restangular Local Storage Interceptor Issue -


i using restangularprovider set $http interceptor inject authentication header restangular requests. problem cannot inject services app.config(), cannot access angular local storage using store token after login server.

angular.module('app').config(function(restangularprovider, localstorageservice) {     restangularprovider.setbaseurl('/api/');      restangularprovider.setfullrequestinterceptor(function(element, operation, route, url, headers, params, httpconfig) {        var authdata = localstorageservice.get('authorizationdata');//error:localstorageservice doesn't exist         }; }); 

"authorizationdata" authentication token stored locally. can see, need able use restangular provider , local storage. appreciate workarounds. thank you!

basically can't inject service angular configuration .config phase. providers/constant accessible config phase(providers meant configurable service)

to solve problem, either transfor localstorageservice provider instead of service/factory, , inject config block localstorageprovider.

other way around achieve is, use $injector retrieve instance of localstorageservice. need inject $injector , use var

localstorageservice = $injector.get('localstorageservice');  

for getting instance of localstorageservice


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -