import {Directive, Input, EventEmitter, ElementRef, Renderer, Inject, AfterViewInit, OnChanges } from '@angular/core'; @Directive({ selector: '[focus]' }) export class FocusDirective implements OnChanges { @Input('focus') focus: boolean; constructor(@Inject(ElementRef) private element: ElementRef, private renderer: Renderer) { } ngOnChanges() { if (this.focus) { this.renderer .invokeElementMethod(this.element.nativeElement, 'focus', []); } } }