我正在使用 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(() => {
}),
);
}
}
我厭倦了 2 個不同的攔截器,但仍然無法弄清楚如何為每個目的使用特定的攔截器
uj5u.com熱心網友回復:
您不能根據呼叫者禁用攔截器,一種方法是通過 API 路徑進行過濾。
另一種方法是 HttpContext https://dev.to/angular/what-the-heck-is-httpcontext-in-angular-4n3c
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/522009.html
