There's a lot of good discussion here, but I can't find a good recommendation.
How to I focus an input or textarea that angular brings in? If I do it in the linking (postlink) function, the $digest cycle is already in progress. Doing it in a timeout works but smells bad. $safeApply has been dis-recommended for checking the $$phase. (https://coderwall.com/p/ngisma) The problem is common enough, what's a good solution? On Monday, February 4, 2013 9:26:25 PM UTC-8, Broc Seib wrote: > > Hi all, > > I'd like to see some official support in Angular for setting focus on > elements. This can address the same problem for blur() and select() at the > same time. Here's the short version of the proposition -- it would look > like: > > 1: <input type="text" x-ng-model="form.color" > x-ng-target="form.colorTarget"> > > 2: <button class="btn" x-ng-click="form.colorTarget.focus()">do > focus</button> > > > I have some evidence (i.e. I've implemented it) that this directive will > work inside ng-repeat too. > > The other aspect to this that I would like to address is a timing issue. > But it means assigning $watch callbacks a priority. The timing problem is > when you "show" or "enable" and element followed immediately by a set > focus. We need to be able to influence the order of these events. > > After I started to look into this, I blogged in (too much) detail here: > http://goo.gl/4rdZa > > In this thread I'd like to hear discussion on two things: > 1) I would like to hear if changing $watch to have a priority is the > right place to address the timing problem. > 2) I would like to hear how the community feels about having an > "official" way of applying focus, blur, and select. > > I feel it would be nice to have an "official" way of doing this common > thing. > > Broc > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
