Select input shown with ng-show

2019-09-06 03:31发布

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

2条回答
霸刀☆藐视天下
2楼-- · 2019-09-06 04:04

You can write a simple directive , dont need jquery :

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

and You can use it like this :

    <input type="text" focusme>
查看更多
混吃等死
3楼-- · 2019-09-06 04:09

If you want the input to be automatically focused when it is shown use the html5 autofocus attribute:

查看更多
登录 后发表回答