Angular 2+订阅错误此上下文

时间:2018-04-11 14:05:48

标签: javascript angular rxjs

我有这个代码,它调用REST API:

是名为

的组件中的方法
load(loadParams: IDatatableLoadEvent): void {
  this.loading = true;
  this.productService.loalProducts(loadParams.sortBy, loadParams.currentPage, loadParams.pageSize, loadParams.searchTerm, loadParams.sortOrder.toLowerCase())
    .subscribe((res: HttpResponse<IProduct[]>) => {
      this.filteredData = res.body;

      // we have to set x-pagination to COSR rules on API server
      const xPagination = res.headers.get('x-pagination');
      this.filteredTotal = JSON.parse(xPagination).totalCount;

      this.loading = false;
      // Hack - because we are setting loading and until data are loaded
      // we have to stop changeDetection and tell angular when to detect changes
      // - this happens only when we are changing pagesize
      this.cdr.detectChanges();
    }, error => {
      this.loading = false;
      console.log(error);
    });
}

问题是,当我收到错误时,错误处理事件被触发,但上下文不是该组件,但是 SafeSubscriber

0 个答案:

没有答案