HttpInterceptors的顺序

Fer*_*ndo 3 angular-http-interceptors angular angular-httpclient

我有一个使用注册了HttpInterceptor的插件的应用程序。

现在,我需要创建自己的拦截器,该拦截器必须在其他拦截器之前运行因为它将更改其他拦截器使用的localStorage中的某些值。

注册新的HttpInterceptor时如何影响执行顺序?

Tal*_*mid 21

https://angular.io/guide/http-intercept-requests-and-responses#interceptor-order

Angular 按照您提供拦截器的顺序应用拦截器。如果您提供拦截器 A、B、C,则请求将在 A->B->C 中流动,而响应将在 C->B->A 中流动。


Ant*_*sss 7

您无法设置拦截器顺序。拦截器按声明的顺序链接在一起。

您将编写自己的超级拦截器,该超级拦截器将为子拦截器添加一些排序逻辑。

  • 所以你的意思是,你可以通过按特定顺序声明拦截器来设置它们的顺序。 (13认同)