File

src/app/shared/directives/autofocus.directive.ts

Implements

AfterViewInit

Metadata

Selector [autofocus]

Index

Methods

Constructor

constructor(elementRef: ElementRef)
Parameters :
Name Type Optional
elementRef ElementRef No

Methods

ngAfterViewInit
ngAfterViewInit()
Returns : void
import { AfterViewInit, Directive, ElementRef } from '@angular/core';

import * as _ from 'lodash';

@Directive({
  selector: '[autofocus]' // tslint:disable-line
})
export class AutofocusDirective implements AfterViewInit {
  constructor(private elementRef: ElementRef) {}

  ngAfterViewInit() {
    const el: HTMLInputElement = this.elementRef.nativeElement;
    if (_.isFunction(el.focus)) {
      el.focus();
    }
  }
}

result-matching ""

    No results matching ""