Send a token that I get from the url stateParams with every request. For this i'm using an http Interceptor.
The interceptor looks like this:
.factory('myInterceptor', function($stateParams){
return {
request: function(config){
config.url = config.url + '?text=' + $stateParams.token;
return config;
}
}
})
Inside the interceptor, the $stateParams is empty when $http is called inside the resolve. However when I call it from inside the controller, it works fine.
Working example:
Using $http inside the controller: http://jsfiddle.net/sikko/drLg06w8/8/
controller: function ($scope, $http) {
$http.post('/echo/jsonp').success(function(response){
$scope.text = response.text;
});
}
Non Working example:
Using $http inside the resolve: http://jsfiddle.net/sikko/drLg06w8/7/
resolve: {
resolveVar: function($http){
return $http.post('/echo/jsonp').success(function(response){
return response.text;
});
}
},
controller: function ($scope, resolveVar) {
$scope.text = resolveVar.data.text;
}
I did console.log in both examples so you can see that $stateParams is empty when using resolve.
My Guess is that the resolve cycle is called before that $stateParams is made available by angular or something like that... But I have no clue how to fix it... Any help would be much appreciated!