I need to be able to switch focus to an input element when some event occurs. How do I do that in Angular 2?
For example:
You can do this just passing the second input as a variable to the first one
For example
HTML
Later in your js/ts
@Component({
selector: 'plunker-app'
})
@View({
templateUrl: 'main.html'
})
class PlunkerApp {
constructor() {
}
processKeyUp(e, el) {
if(e.keyCode == 65) { // press A
el.focus();
}
}
}
el is the raw element, so you can use pure javascript on it.
Here's a plnkr so you can see it working.
I hope it helps.