0

I'd like to put the focus on an input after it's shown with ng-show. However, this requires a jquery call to be made after the $digest cycle. Does anyone know how to run code after the item is shown, without resorting to setTimeout(), or some such thing? Here's an example plunk of the issue: http://plnkr.co/edit/synSIP?p=preview

4

2 回答 2

1

您可以编写一个简单的指令,不需要 jquery:

  yourApp.directive('focusme',function(){
   return function(scope,elem,att){
      elem.focus();
   }
  });

你可以像这样使用它:

    <input type="text" focusme>
于 2014-06-18T16:34:59.553 回答
-1

如果您希望输入在显示时自动聚焦,请使用 html5 autofocus 属性:

于 2014-06-18T15:31:47.887 回答