Angular 如何使用router处理4xx错误。在observable中导航。角度2

Angular 如何使用router处理4xx错误。在observable中导航。角度2,angular,rxjs,Angular,Rxjs,router.navigate在handleError函数中出现错误后无法工作 可观测方法 getAll(): Observable<any[]> { return this._http.get('/api/getall' ) .map((response: Response) => <any[]>response.json()) .do(data => console.log("All: " + JSON.string

router.navigate在handleError函数中出现错误后无法工作

可观测方法

getAll(): Observable<any[]> {
    return this._http.get('/api/getall' )
        .map((response: Response) => <any[]>response.json())
        .do(data => console.log("All: " + JSON.stringify(data)))
        .catch(this.handleError);
}

如果要在
handleError
中使用
this
,则需要以不同的方式传递函数

getAll():可观察{
返回此值。_http.get('/api/getall')
.map((response:response)=>response.json())
.do(data=>console.log(“All:+JSON.stringify(data)))
抓住(这个)手,绑(这个);
//.catch(err=>this.handleError(err));
}
在我更改后

.catch(this.handleError.bind(this));

.catch(this.handleError.bind(this));
这工作正常

谢谢@günter-zöchbauer

谢谢,但当我添加“.catch(this.handleError.bind(this))”时,出现了以下错误:类型observable与类型observable不可分。类型{}不能赋值给boolean@günter-zöchbauer类型
.catch(this.handleError.bind(this));
.catch<any[]>(this.handleError.bind(this));