【发布时间】:2018-10-16 23:01:55
【问题描述】:
升级到 Angular 6.0 和 Rxjs 到 6.0 后,我收到以下编译错误:
Property 'do' does not exist on type 'Observable'.
代码如下:
import { Observable, of } from 'rxjs';
import 'rxjs/add/operator/do';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/catch';
import { IProduct } from './product';
@Injectable()
export class ProductService {
constructor(
private product: IProduct)
{
}
getProduct = () => {
return product.products
// error on next line
.do(data => console.log('All:' + JSON.stringify(data)))
.catch(this.handleError);
}
private handleError(err: HttpErrorResponse) {
console.log(err.message);
return Observable.throw(err.message);
}
}
有什么想法吗?
【问题讨论】:
-
你能分享一个最小的代码示例来说明这个问题吗?这对于帮助我们调试正在发生的事情大有帮助!
-
import { tap } from "rxjs/operators";试试这个return next.handle(clonedReq).pipe(tap((err: any) => { }));