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

100% Statements 10/10
66.67% Branches 2/3
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1892x   92x         92x 168x   92x 165x   165x     92x  
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();
    }
  }
}