我有一个自动完成输入域,它对用户输入做出react 并执行搜索功能.我设置了一个过滤器,以便只有在输入值超过两个字符时才开始搜索.因为我在*ngFor
循环中显示了options$
,所以如果过滤器触发,我想返回一个空数组,所以下拉列表不会显示任何结果.
如果用户开始打字,这很好用,但如果他们删除了整个输入,最后一次搜索的结果仍然可见.
So basically what I would like to do is return an empty array, if the filter statement triggers.个
public control = new FormControl()
this.options$ = this.control.valueChanges.pipe(
debounceTime(300),
distinctUntilChanged(),
filter((val) => val.length > 2),
switchMap((search) => this.filterFunc<T>(search))
);
我试图引入另一个布尔值,它可以处理下拉列表的打开和关闭状态,但我认为必须有一种方法来实现这一点,而不需要强制设置值.