我和Angular13一起工作,ngrx 13。
我正在执行来自app.module.ts的API调用。
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MyHttpInterceptor,
multi: true,
}
{
provide: APP_INITIALIZER,
useFactory: (store: Store<IStore>) => {
return () => store.dispatch(MyAction.getData());
},
deps: [Store],
multi: true
},
]MyHttpInterceptor
@Injectable()
export class MyHttpInterceptor implements HttpInterceptor {
constructor() {}
public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// Here I need add something conditionally.
// I mean if the Http call is based on App initializer
// For normal Http API calls from components using ngrx can ignore this condition
if(isAppInitialize == true) {
}
return next.handle(req).pipe(
finalize(() => {
}),
);
}
}我厌倦了两种不同的截止器,但仍然想不出我如何才能为每一种目的使用特定的阻断器。
发布于 2022-10-27 08:11:07
不能基于调用者禁用拦截器,一种方法是通过API路径进行筛选。
另一种方法是HttpContext https://dev.to/angular/what-the-heck-is-httpcontext-in-angular-4n3c
https://stackoverflow.com/questions/74218640
复制相似问题