nts-ng2-components
Version:
Paquete de componentes para Angular2 desarrollado por NITSNETS.
26 lines (21 loc) • 681 B
text/typescript
import { Directive, ElementRef, Input, OnInit, Renderer } from '@angular/core';
export class NtsAutofocusDirective implements OnInit {
autofocus = false;
constructor(
private elementRef: ElementRef,
private renderer: Renderer
) { }
ngOnInit() {
const elm = this.elementRef.nativeElement;
if (this.autofocus) {
this.renderer.invokeElementMethod(elm, 'focus', []);
/* Hack to prevent Firefox put the cursor at the beggining of the input */
const value = elm.value;
elm.value = '';
elm.value = value;
}
}
}