I'm building an Angular Reactive Form and I have an input of type number. I have provided Validators.min(0) to the FormControl, however when I focus the input and scrolls down or holds the Arrow down button the value goes bellow 0. Is it a bad practice to combine Angular Validators with native html validator like min.
Here is what I have at the moment
HTML
<input type="number" formControlName="quantity">
TS
quantity: this.fb.control(null, [Validators.required, Validators.min(0)]),
And this is what I have tried
HTML
<input type="number" min="0" formControlName="quantity">
TS
quantity: this.fb.control(null, [Validators.required, Validators.min(0)]),
It seems to work ok, still not sure if it is considered a bad practice and if there are any pitfalls in this approach.
For this scenario it's OK, because maximum you are going to get the same validation added twice, which is not a problem. You are simply using the HTML attribute for limiting negative values and not for doing extra validations that could simply be done with reactive form validations.
So your code change is fine, in my opinion. We could also write an Angular directive that blocks negative values, this is a simpler solution:
Stackblitz Demo