當我subscirbe形成並等待突破,如果我resonse是從我的服務偏差值發生改變......錯誤響應休息valueChanges [Angular2]
這裏是代碼:
constructor(private fb: FormBuilder, private bankService: BankService) {
this.page = 1;
this.filter = this.fb.group({
text: ['', []],
bankC: ['', []]
});
this.filter.valueChanges
// wait for a pause in typing of 200ms then emit the last value
.debounceTime(200)
// only accept values that don't repeat themselves
.distinctUntilChanged()
// map that to an observable HTTP request, using the TickerLoad
// service and switch to that
// observable. That means unsubscribing from any previous HTTP request
// (cancelling it), and subscribing to the newly returned on here.
.switchMap((val: any) => {
return bankService.getCountry(val.bankC)
})
.subscribe((res) => {
console.log(res);
},
(err) => {
console.log(err);
});
// send an empty array to tickers whenever clear emits by
// merging in a the stream of clear events mapped to an
// empty array.
}
編輯
我找到職高的問題,它是http intreceptor裏面是什麼:
intercept(observable: Observable<Response>): Observable<Response> {
return observable.catch((err, source) => {
if (err.status == 401) {
this._router.navigate(['']);
return Observable.throw(err);
//&& !_.endsWith(err.url, 'api/auth/login')
} else {
return Observable.throw(err);
}
});
}
這是這個零件:return Observable.throw(err);
我怎樣才能返回沒有制動訂閱的錯誤。
什麼錯誤,以及如何打破? – martin
服務器返回404錯誤,之後:this.filter.valueChanges不起作用。它只是停止'console.log' –
錯誤是否達到'console.log(err);'? – martin