相关疑难解决方法(0)

'Observable <IProduct []>'类型中不存在属性'do'

升级到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);        
    }
}
Run Code Online (Sandbox Code Playgroud)

任何的想法?

angular rxjs6

31
推荐指数
4
解决办法
3万
查看次数

如何使用角度为4.3的新httpClient处理未经授权的请求(状态为401或403)

我有一个auth-interceptor.service.ts处理请求

import {Injectable} from '@angular/core';
import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';
import {Cookie} from './cookie.service';
import {Router} from '@angular/router';

@Injectable()
export class AuthInterceptor implements HttpInterceptor {
    constructor(private router: Router) {}
    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        // Clone the request to add the new header.
        const authReq = req.clone({headers: req.headers.set(Cookie.tokenKey, Cookie.getToken())});
        // Pass on the cloned request instead of the original request.
        return next.handle(authReq).catch(this.handleError);
    }

    private handleError(err: HttpErrorResponse): Observable<any> {
        console.log(err);
        if …
Run Code Online (Sandbox Code Playgroud)

typescript angular-http angular-http-interceptors angular angular-httpclient

12
推荐指数
2
解决办法
2万
查看次数