Primeng 下拉式自动对焦
Primeng dropdown autofocus
我的 angular 应用程序中有一个来自 PrimeNG 的下拉菜单。此下拉菜单已将 autofocus
属性 设置为 true。
所以,当我打开我的组件(或对话框)时,里面有这个下拉菜单,一切正常,下拉菜单有焦点,我可以通过按键 select 选项。
但是当我去应用程序的其他地方然后返回带有下拉菜单的组件(或重新打开对话框)时,下拉菜单上的自动对焦没有设置(我检查过现在焦点设置在文档正文上)。
有没有可能解决这个问题?
好的,我明白了。
在我有下拉菜单的组件中,我添加:
@ViewChild('dropdown') dropdown: Dropdown;
然后当加载组件时(或打开对话框 - 在 onShow
事件中)我使用了 Dropdown 中的方法:
this.dropdown.applyFocus();
我的 angular 应用程序中有一个来自 PrimeNG 的下拉菜单。此下拉菜单已将 autofocus
属性 设置为 true。
所以,当我打开我的组件(或对话框)时,里面有这个下拉菜单,一切正常,下拉菜单有焦点,我可以通过按键 select 选项。
但是当我去应用程序的其他地方然后返回带有下拉菜单的组件(或重新打开对话框)时,下拉菜单上的自动对焦没有设置(我检查过现在焦点设置在文档正文上)。
有没有可能解决这个问题?
好的,我明白了。
在我有下拉菜单的组件中,我添加:
@ViewChild('dropdown') dropdown: Dropdown;
然后当加载组件时(或打开对话框 - 在 onShow
事件中)我使用了 Dropdown 中的方法:
this.dropdown.applyFocus();