Preface:
My motivation for asking the questions below stems from my experience with form.value.purchaseCost
. When the <input>
field does not have type=number
, I receive a string instead of a number. This required me to manually convert it to Number
in order to validate the field. Initially, I assumed Angular would store the value as a number in the form due to the presence of a Validators.min
constraint on it.
Question
This is how the field is defined:
<mat-form-field>
<input matInput type="number" formControlName="purchaseCost" placeholder="Purchase cost*">
<mat-error>Please enter a purchase cost</mat-error>
</mat-form-field>
Here is the validation check:
purchaseCost: new FormControl('', [Validators.required, Validators.min(0)]),
With the field being of type="number"
, does the FormControl
automatically perform a conversion before checking if the entry in the field is greater than 0 (min(0)
)?
Furthermore, when we retrieve form.value.purchaseCost
, do we need to manually convert purchaseCost
to a number before using it, or does Angular Reactive Forms handle this since the field has type=number
?
In summary, does Angular Reactive Forms store the value in the type specified by the <input>
field?