问题:
What is the 'Angular way' to set focus on input field in AngularJS? 在AngularJS中将焦点设置在输入字段上的“角度方式”是什么?
More specific requirements: 更具体的要求:
- When a Modal is opened, set focus on a predefined
<input>
inside this Modal. 打开模态后 ,将焦点放在此模态内的预定义<input>
。 - Everytime
<input>
becomes visible (eg by clicking some button), set focus on it. 每当<input>
变为可见时(例如,通过单击某些按钮),请将焦点设置在它上面。
I tried to achieve the first requirement with autofocus
, but this works only when the Modal is opened for the first time, and only in certain browsers (eg in Firefox it doesn't work). 我试图通过autofocus
达到第一个要求 ,但这仅在首次打开Modal时有效,并且仅在某些浏览器中有效(例如,在Firefox中不起作用)。
Any help will be appreciated. 任何帮助将不胜感激。
解决方案:
参考一: https://stackoom.com/question/10EpC/如何设置对输入字段的关注参考二: https://oldbug.net/q/10EpC/How-to-set-focus-on-input-field
来源:oschina
链接:https://my.oschina.net/stackoom/blog/4254076