import { Directive , ElementRef , OnInit } from '@angular/core' ; @ Directive ( { selector : '[autofocusOnShow]' , } ) export class FocusOnShowDirective implements OnInit { constructor ( private el ) { if ( ! el . nativeElement [ 'focus' ] ) { throw new Error ( 'Element does not accept focus.' ) ; } } ngOnInit ( ) { const input = this . el . nativeElement as HTMLInputElement ; input . focus ( ) ; input . select ( ) ; } }