<mat-autocomplete
autoActiveFirstOption
#auto="matAutocomplete"
>
<mat-option
*ngFor="let option of filteredOptions | async"
[value]="option.id"
>
{{option.title}}
</mat-option>
</mat-autocomplete>
createdFiltered() {
const lessonNameControl = this.lessonInfo.get("seriesName");
this.filteredOptions = lessonNameControl.valueChanges.pipe(
startWith(""),
map(value => {
// searchSeries 是一个rxjs请求,这个请求会返回一个数组,但是由于异步原因,并无法获取到这个数组
return this.searchSeries(value);
})
);
}
在这个函数中,我希望this.filteredOptions是一个数组,问题如代码中描述的样子
把Observerable转换为Promise就可以用async。但你这个地方没必要用async。
你这里不能用map,应该用flatMap。searchSeries返回一个Observerable来异步获取数值。