Select input shown with ng-show

跟風遠走 提交于 2020-01-16 19:14:46

问题


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


回答1:


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>



回答2:


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



来源:https://stackoverflow.com/questions/24289266/select-input-shown-with-ng-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!