[英]Select input shown with ng-show
I'd like to put the focus on an input after it's shown with ng-show. 我想把重点放在ng-show显示的输入上。 However, this requires a jquery call to be made after the $digest cycle.
但是,这需要在$ digest循环之后进行jquery调用。 Does anyone know how to run code after the item is shown, without resorting to setTimeout(), or some such thing?
有谁知道在项目显示后如何运行代码,而不求助于setTimeout()或类似的东西? Here's an example plunk of the issue: http://plnkr.co/edit/synSIP?p=preview
这是该问题的一个小例子: http ://plnkr.co/edit/synSIP? p= preview
You can write a simple directive , dont need jquery : 您可以编写一个简单的指令,不需要jquery:
yourApp.directive('focusme',function(){
return function(scope,elem,att){
elem.focus();
}
});
and You can use it like this : 您可以像这样使用它:
<input type="text" focusme>
如果您希望输入在显示时自动聚焦,请使用html5 autofocus属性:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.