我在valueCnage处有一个输入框,它调用一个调用API的异步函数。
this.searchFrom = new FormGroup({
ss: new FormControl()
});
this.searchFrom.valueChanges
.pipe(debounceTime(500))
.pipe(distinctUntilChanged())
.subscribe((b) => {
this.search(b);
});
search(ss: string) {
console.log("📡 API");
this.http.post(endpoint + 'search', { 'ss': ss })
.toPromise()
.then((data) => {
this.data = data;
console.log(data);
return data;
})
.catch((err) => {
console.error(err);
})
.finally(() => {
console.log("✅✅");
});
}
It just calls funtion, it dont calls .then
In console.log I get only:
> 📡 API
您应该了解rxjs及其操作符。
这是一个可行的解决方案:
不知道为什么将可观察的东西转化为承诺,无论如何,我有另一种方法来解决您的问题,
尝试这个