[英]completeMethod event not triggering in primeNG Autocomplete on focus
I am trying to use the autocomplete component in my application.我正在尝试在我的应用程序中使用自动完成组件。 The autocomplete in the HTML looks something like this:
HTML 中的自动完成看起来像这样:
<p-autoComplete [(ngModel)]="student" name="basic"
[suggestions]="filteredStudents"
(completeMethod)="filterStudents($event)"
field="name" [size]="30"
placeholder="Select student" [minLength]="0">
</p-autoComplete>
If you notice I have specified the "minLength" as 0. The need for this was to try load the suggestions as soon as I focus on the autocomplete input field (non-filtered of course).如果您注意到我已将“minLength”指定为 0。这样做的需要是在我专注于自动完成输入字段(当然未过滤)时尝试加载建议。 But unfortunately this does not happen.
但不幸的是,这不会发生。 Interestingly though when I enter some characters and clear them off the suggestions appear as expected.
有趣的是,当我输入一些字符并将它们清除时,建议会按预期显示。 Anything which I might be doing wrong here?
我在这里可能做错了什么?
Just a note that I also tried to make use of the "onFocus" event which too did not work.请注意,我也尝试使用“onFocus”事件,但它也不起作用。
TIA TIA
Using handleDropdownClick()
can be used as workaround.使用
handleDropdownClick()
可以用作解决方法。
<p-autoComplete #ac [(ngModel)]="student" name="basic"
[suggestions]="filteredStudents"
(onFocus)="triggerOverlayPanel(ac)"
(completeMethod)="filterStudents($event)"
field="name" [size]="30"
placeholder="Select student" [minLength]="0">
</p-autoComplete>
ts file. .ts 文件。
AutoComplete ref trigger handleDropdownClick()
as if user clicked on dropdown and as argument add self. AutoComplete ref 触发器
handleDropdownClick()
就像用户单击下拉列表并作为参数添加 self.
triggerOverlayPanel(ac: AutoComplete){
// condition added to check if no chars need to display result
if(ac.minLength === 0) {
ac.handleDropdownClick(ac);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.