2 回答

TA貢獻1831條經(jīng)驗 獲得超9個贊
您應(yīng)該了解 rxjs 及其運算符。
這里有一個可行的解決方案:
this.searchFrom = new FormGroup({
ss: new FormControl()
});
this.searchFrom.valueChanges
.pipe(
debounceTime(500),
distinctUntilChanged(),
switchMap(x => this.search(x.ss))
).subscribe((result) => {
// result contains HTTP-result if non Error
});
search(ss: string) {
console.log("?? API");
return this.http.post(endpoint + 'search', { 'ss': ss });
}

TA貢獻1828條經(jīng)驗 獲得超13個贊
不知道為什么你要把你的可觀察性轉(zhuǎn)化為承諾,無論如何,我有另一種方法可以解決你的問題,
試試這個
this.searchFrom.valueChanges.pipe(
map(value => value.ss),
debounceTime(500),
distinctUntilChanged(),
switchMap(search => this.search(search))
).subscribe(data => console.log(data));
search(ss: string) {
return this.http.post(endpoint + 'search', { 'ss': ss })
}
添加回答
舉報