RXJS 디 바운싱을 사용한 간단한 검색 방법이 있습니다.서비스에서 오류 발생 후 변경 방법이 호출되지 않습니다.
이렇게하면됩니다.
this.searchTerm.valueChanges
.debounceTime(this._debounceDelay, this._scheduler)
.distinctUntilChanged()
.filter(this.filterForBlank.bind(this))
.filter(this.filterForLength.bind(this))
.switchMap(term => this.searchService.serchBy(term))
.subscribe((data) => {
// do something
}, (err) => {
// show error on UI
});
private filterForLength(term: string) {
return (term.trim().length > 2);
}
private filterForBlank(term: string) {
if (isEmpty(term)) {
return false;
}
return true;
}
하지만 오류가있는 경우 (예 : URL을 잘못된 것으로 변경 한 경우 ...이 변경 기능이 다시 작동하지 않음) 심지어 값을 변경 한 후에도
나는 오류가 있으면 관찰 할 수 없게 죽일 필요가 있다고 생각합니다. 그러나 정확하게 이것을 달성하는 방법을 모르십시오.
작동하지 않습니다! 잡으려고하지만 값을 변경 한 후에 다시 API를 호출하지 않습니다. –