Мне нужно иметь возможность переключать фокус на элемент ввода, когда происходит какое-то событие. Как это сделать в Angular 2?
Например:
<input (keyUp)="processKeyUp($event)"/>
<input (focusme)="alert('i am focused')"/>
Я хочу сфокусировать второе поле ввода, когда в первом нажата определенная клавиша. Я думаю, что мне нужно использовать настраиваемое событие (focusme
в фрагменте), но я не знаю, где и как его объявить, и использовать ли для него аннотацию @Directive
или включить его определение в компонент как-то. Короче говоря, я в тупике.
UPDATE
Забыл упомянуть, я знаю, что могу это сделать, используя локальные переменные в html, но я хочу иметь возможность сделать это из компонента, и я хочу иметь возможность выполнять сложную логику при запуске focusme
чтобы контролирующие его прослушивание могли определить, предназначено ли оно для них или нет.
Спасибо!