A
A
Artem Shchurin2015-06-05 15:41:42
JavaScript
Artem Shchurin, 2015-06-05 15:41:42

How to trigger focus event on input in angular?

Hello!
I’m familiar with angular recently, I want to do this:
$('input').focus()
I read it more than once, they say you don’t need to change from the DOM controller, all its changes go through the view
among the standard directives, I didn’t find one that could set focus on an element when a certain condition is met,
how to get out of this situation ?
write your own directive?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-06-05
@schurin

write your own directive?

Yes exactly.
angular.module('app')
    .directive('focusOnEnter', focusOnEnter)
;

function focusOnEnter() {
     return (scope, el) => {
         el.focus();
     }
};

<input focus-on-enter type="text" />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question