Input field accepting only numbers without firing events when input other caracters
问题 I'm not satisfied with the default behavior of the html number input, I would like to have a simple input that accepts only numbers. I created this directive : import { Directive, ElementRef, HostListener, Input } from '@angular/core'; import { NgControl } from '@angular/forms'; @Directive({ selector: 'input[numbersOnly]' }) export class NumberDirective { constructor(private _el: ElementRef) { } @HostListener('input', ['$event']) onInputChange(event) { const initalValue = this._el