当要使用自动完成功能时,如何避免在输入时触发搜索?角度 HTML

发布于 2025-01-12 08:55:09 字数 775 浏览 3 评论 0原文

我正在尝试使用 Enter 进行自动完成,然后能够使用 Enter 搜索我的输入。当应选择自动完成时,如何才能不使用 Enter 触发搜索?目前,在第一次选择自动完成之后,两者会同时触发。

HTML:

<input placeholder="Addera kompetenser..." #competenceInput [formControl]="competenceCtrl" [matAutocomplete]="auto" [matChipInputFor]="chipList" [matChipInputSeparatorKeyCodes]="separatorKeysCodes" (keydown.enter)="serachTriggerEnter()" (matChipInputTokenEnd)="add($event)">

TS:

separatorKeysCodes: number[] = [ENTER];

serachTriggerEnter() {
    this.searchCompetences(); 
}

add(event: MatChipInputEvent): void {
    const value = event.value 
    this.addToArray(value);
    event.chipInput!.clear();
    this.competenceCtrl.setValue(null);
}

如果您希望我添加信息以便更容易理解我的问题,请随时询问我!

提前致谢。

I am trying to have an autocomplete with enter and then be able to search with enter for my input. How can I not trigger the search with enter when an autocomplete should be chosen? At the moment, both are triggered at the same time, already after first chosen autocomplete.

HTML:

<input placeholder="Addera kompetenser..." #competenceInput [formControl]="competenceCtrl" [matAutocomplete]="auto" [matChipInputFor]="chipList" [matChipInputSeparatorKeyCodes]="separatorKeysCodes" (keydown.enter)="serachTriggerEnter()" (matChipInputTokenEnd)="add($event)">

TS:

separatorKeysCodes: number[] = [ENTER];

serachTriggerEnter() {
    this.searchCompetences(); 
}

add(event: MatChipInputEvent): void {
    const value = event.value 
    this.addToArray(value);
    event.chipInput!.clear();
    this.competenceCtrl.setValue(null);
}

If you want me to add information to make it easier to understand my question, please do not hesitate to ask me!

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文