2
是否可以從HttpInterceptor
調用組件中的函數?從HttpInterceptor中調用組件的函數?
@Injectable()
export class HttpResponseInterceptor implements HttpInterceptor {
// constructor(@Inject(DOCUMENT) private document: any) { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('HttpRequest<any> called');
const started = Date.now();
// Call component function
return next.handle(req).do((event: HttpEvent<any>) => {
if (event instanceof HttpResponse) {
// Call component function on response
}
});
}
}
如果你想重用的功能,請嘗試設置功能在服務 –
我不知道,但好主意是whorte的機能的研究服務和共享在攔截器和組件,如果可能。 –