我注意到我的代码在新项目中使用时不起作用:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { TypeAndCountURL } from '@app/constants';
import { HttpErrorService } from '@app/services/http-error.service';
import { TypeAndCountResponseBody, TypeAndCountRequestBody } from '@app/models/type-and-count/bodies.interface';
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor (private http: HttpClient, private httpErrorService: HttpErrorService) {}
postTypeAndCountRequest(typeAndCountRequestBody: TypeAndCountRequestBody): Observable<TypeAndCountResponseBody> {
return this.http.post<TypeAndCountResponseBody>(TypeAndCountURL, typeAndCountRequestBody).pipe(
catchError(this.httpErrorService.handleError<TypeAndCountResponseBody>('postTypeAndCountRequest'))
);
}
}
具体来说,我得到 Cannot find name 'catchError'. Did you mean 'RTCError'?ts(2552)
读到这里,我发现我可以通过单独导入来解决这个问题(从 rxjs/operators .. whihc 很好,但是).. 而且整个结构是 rxjs 5 的兼容模式......是什么RXJS 6 处理错误响应的方式?
BIG阳
相关分类