solo numero
unknown
plain_text
4 years ago
501 B
9
Indexable
import { Directive, ElementRef, HostListener } from '@angular/core';
@Directive({
selector: 'input[appNumbersOnly]'
})
export class OnlyNumberDirective {
constructor(private el: ElementRef) { }
@HostListener('input', ['$event']) onInputChange(event) {
const initalValue = this.el.nativeElement.value;
this.el.nativeElement.value = initalValue.replace(/[^0-9]*/g, '');
if ( initalValue !== this.el.nativeElement.value) {
event.stopPropagation();
}
}
}
Editor is loading...