import { Component, ElementRef, ViewChild, AfterContentInit } from '@angular/core';
@Component({
selector: 'custom-form',
template: `
<form>
<input
placeholder="Name"
#nameInput
/>
</form>
`
})
export class FormComponent implements AfterContentInit {
@ViewChild('nameInput') nameInput: ElementRef;
// Change state before angular change detection complete
ngAfterContentInit() {
this.nameInput.nativeElement.focus();
}
}