import { Directive , OnInit , ElementRef } from '@angular/core' ; @ Directive ( { selector : '[focus]' } ) export class FocusDirective implements OnInit { constructor ( private elementRef ) { } ngOnInit ( ) { this . elementRef . nativeElement . focus ( ) ; } ngAfterViewInit ( ) { setTimeout ( ( ) => this . elementRef . nativeElement . focus ( ) , 500 ) ; } }