Home > Software design >  Angular- How to prevent text in input from showing if input is invalid
Angular- How to prevent text in input from showing if input is invalid

Time:01-15

I have an input text tag with [(ngModel)]=some_var . When the user inputs something that isn't a number or decimal, I want it to not show in the input box when typing. For example, if I type h in the text box I don't want to see h as I type it (if that makes sense).

I'm not sure which event to use.

CodePudding user response:

If you only want numbers and dot as a decimal separator, you can just use:

<input type="number" (...) >
  •  Tags:  
  • Related