Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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
AngularJS 1.3.13-是否可以向特定的$resource添加多个拦截器?_Angularjs_Angularjs Routing - Fatal编程技术网

AngularJS 1.3.13-是否可以向特定的$resource添加多个拦截器?

AngularJS 1.3.13-是否可以向特定的$resource添加多个拦截器?,angularjs,angularjs-routing,Angularjs,Angularjs Routing,我有很多不同的拦截器,我只想在特定的$resource端点上使用它们。我阅读了$resource的interceptor属性,并使其正常工作,但在一些情况下,我希望为一个端点响应准备两个拦截器,就像普通的全局拦截器一样。这可能吗 在用户$resource的操作中,我希望将类似于我已添加到登录端点的内容: var actions = { login: { method: 'POST', url: '/api/auth/login', int

我有很多不同的拦截器,我只想在特定的$resource端点上使用它们。我阅读了$resource的interceptor属性,并使其正常工作,但在一些情况下,我希望为一个端点响应准备两个拦截器,就像普通的全局拦截器一样。这可能吗

在用户$resource的操作中,我希望将类似于我已添加到登录端点的内容:

var actions = {

    login: {
        method: 'POST',
        url: '/api/auth/login',
        interceptor: [AuthLoginInterceptor,AuthUserInterceptor]
    },
    logout: {
        method: 'GET',
        url: '/api/auth/logout',
        interceptor: AuthLogoutInterceptor
    },
    update: {
        method: 'PUT',
        interceptor: AuthUserInterceptor
    },...

我知道我可以将其中一个的代码包含在另一个中,所以在最坏的情况下,我只需重构一个解决方案,但如果可能的话,我宁愿保持原样。

像这样的东西怎么样

{
  method: 'POST',
  url: '/api/auth/login',
  interceptor: {
    response: function (config) {
      return AuthLoginInterceptor.response(AuthUserInterceptor.response(config));
    }
  }
}
它似乎在我使用的最小测试项目中工作



答案基于我上面的评论。希望它能对这个问题的未来访问者有所帮助。

像这样的东西怎么样

{
  method: 'POST',
  url: '/api/auth/login',
  interceptor: {
    response: function (config) {
      return AuthLoginInterceptor.response(AuthUserInterceptor.response(config));
    }
  }
}
它似乎在我使用的最小测试项目中工作



答案基于我上面的评论。希望它能对这个问题的未来访问者有所帮助。

它看起来不像。期望它是一个带有
响应
属性的单个对象,而不适用于数组。除非你能创建一个代码来创建一个能调用多个拦截器的拦截器…嗨@GregL,是的,这就是我想的,好吧。将只进行重构。我相信跳转到另一个拦截器的唯一方法是强制执行一个错误,并在一个为捕获失败的请求和响应而构建的拦截器中捕获它。@mtpultz类似这样的东西怎么样:
{method:'POST',url:'/api/auth/login',拦截器:{response:function(config){return AuthLoginInterceptor.response(AuthUserInterceptor.response(配置));}}}
?它似乎在我使用的一个最小测试项目中工作。嗨@MatthewKing,太棒了!谢谢。出于某种原因,我不再认为这些对象具有可以调用的方法。它看起来不像。它期望它是一个带有
响应
属性的单个对象,并且不适用于数组。U除非你能创建一个代码来创建一个能调用多个拦截器的拦截器……嗨@GregL,是的,这就是我想的,哦,好吧。只需要重构。我相信跳转到另一个拦截器的唯一方法就是强制执行错误,并在一个内置拦截器中捕获它,以捕获失败的请求和响应。@mtpultz例如:
{method:'POST',url:'/api/auth/login',拦截器:{response:function(config){return AuthLoginInterceptor.response(AuthUserInterceptor.response(config));}}}
?它似乎在我正在使用的一个最小的测试项目中工作。嗨@MatthewKing,太棒了!谢谢。出于某种原因,我不再认为这些对象具有可以调用的方法。