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