How to prevent form field to take nagetive value?


#1

In form some this field “ml_right_wall” auto patched to “distance” variable. I want to prevent them if variable assign negative value to form field.

 this.form.controls.ml_right_wall.patchValue(distance);

and want to display that field in red color if value patch comes in negetive

 <ion-input   type="number" min="0" formControlName="ml_right_wall" required clearInput></ion-input>

#2

Explore using validators that you can add to your formGroup. This is an Angular feature. I use this module for my Ionic apps: https://github.com/yuyang041060120/ng2-validation