小编Tus*_*har的帖子

从 HttpInterceptor 调用组件中的函数?

是否可以从 Component 中调用函数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
      }
    });
  }

}
Run Code Online (Sandbox Code Playgroud)

typescript angular-components angular

5
推荐指数
1
解决办法
3536
查看次数

标签 统计

angular ×1

angular-components ×1

typescript ×1