Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度+;Ui路由器:$stateParams在使用resolve时在拦截器内为空 我想要达到的目标:_Javascript_Angularjs_Angular Ui Router_Interceptor - Fatal编程技术网

Javascript 角度+;Ui路由器:$stateParams在使用resolve时在拦截器内为空 我想要达到的目标:

Javascript 角度+;Ui路由器:$stateParams在使用resolve时在拦截器内为空 我想要达到的目标:,javascript,angularjs,angular-ui-router,interceptor,Javascript,Angularjs,Angular Ui Router,Interceptor,在每个请求中发送我从url stateParams获得的令牌。为此,我使用了一个http拦截器 拦截器如下所示: .factory('myInterceptor', function($stateParams){ return { request: function(config){ config.url = config.url + '?text=' + $stateParams.token; return config;

在每个请求中发送我从url stateParams获得的令牌。为此,我使用了一个http拦截器

拦截器如下所示:

.factory('myInterceptor', function($stateParams){
    return {
        request: function(config){
            config.url = config.url + '?text=' + $stateParams.token;
            return config;
        }
    }
})
我的问题 在拦截器内,当在解析内调用$http时,$stateParams为空。但是,当我从控制器内部调用它时,它工作正常

工作示例

在控制器内使用$http:

非工作示例

在解析中使用$http:

我在这两个示例中都添加了console.log,以便您可以看到$stateParams在使用resolve时为空


我猜解析循环是在angular或类似的东西提供$stateParams之前调用的。。。但我不知道如何修复它。。。任何帮助都将不胜感激

您实际在哪里阅读
$stateParams
?工作和非工作示例的完整代码都在JSFIDLE链接上。我将更新问题以澄清。
controller: function ($scope, $http) {
  $http.post('/echo/jsonp').success(function(response){
    $scope.text = response.text;
  });
}
resolve: {
  resolveVar: function($http){
    return $http.post('/echo/jsonp').success(function(response){
      return response.text;
    });
  }
},
controller: function ($scope, resolveVar) {
  $scope.text = resolveVar.data.text;
}