How to restrict alphabets and special characters input in textbox Angular 7? I am sharing an example for allowing only numbers in Textbox Angular 7, following steps involved:- 1. Create Angular directive to allow only numbers input 2. Import this directive in module 3. Use the above-created directive in your components to apply this Let’s see the example – Create Directive to allow only numbers input – import { Directive , ElementRef , HostListener , Input } from '@angular/core' ; import { NgControl } from '@angular/forms' ; @ Directive ({ selector: '[numbersOnly]' }) export class OnlynumberDirective { constructor ( private _el : ElementRef ) { } @ HostListener ( 'input' , [ '$event' ]) onInputChange ( event ) { const initalValue = this . _el . nativeElement . value ; this . _el ....
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers