Select input shown with ng-show
Asked Answered
R

2

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

Raymer answered 18/6, 2014 at 15:16 Comment(2)
could you be a little more specific please as to what your issue is?Procurance
Sorry. Is that better?Raymer
D
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>
Drafty answered 18/6, 2014 at 16:34 Comment(0)
P
-1

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

Procurance answered 18/6, 2014 at 15:31 Comment(1)
That's a good idea. The one problem is that our client base requires the use of non-HTML5-compliant browsers. Also, it only autoselects the first input in the ng-repeat'd list.Raymer

© 2022 - 2024 — McMap. All rights reserved.