import { Directive, ElementRef, OnInit, Self } from '@angular/core';

@Directive({ selector: '[uiAutofocus]', exportAs: 'uiAutofocus' })
export class UiAutofocusDirective implements OnInit {
  get nativeElement() {
    return this.elementRef.nativeElement as HTMLElement;
  }

  constructor(@Self() private elementRef: ElementRef) {}

  ngOnInit() {
    this.focus();
  }

  focus() {
    this.nativeElement.focus();
  }
}
