Skip to content

Instantly share code, notes, and snippets.

@Alos
Last active August 29, 2015 14:11
Show Gist options
  • Save Alos/1822a906bd1a1467b48d to your computer and use it in GitHub Desktop.
Save Alos/1822a906bd1a1467b48d to your computer and use it in GitHub Desktop.
var app = angular.module('Myapp' [
])
.factory ('Foo' , function(MyServiceThatUsesHTTP){
var userDetails = {};
userDetails.setToken(aToken){
this.token = aToken;
}
userDetails.doSomething() = function(){
MyServiceThatUsesHTTP.meh();
};
})
.run(['', function(){
//Here there by dragons
}])
.config('', function(){
//overwite the response interceptor here
$httpProvider.reponseInterceptors.push([
'Foo', function(Foo){ /** PROBLEM because of this */
//...
if(reponse.status ===401 && .......){
//We need to get a new token and save it to our userDetails
$injector.get('$http').jsonp('/my_auth').then(function(response){
if(response){
Foo.setToken(response.mytoken); /** PROBLEM because of this */
}
});
....
}
....
}])
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment