In Angular you can add attributes to inputs and make them optional using attr:
<input [type]="text" [attr.id]="id">
But how do you make a form control optional? I want something like this:
<input [type]="text" [attr.formControl]="someControl">
Where the formControl will not be set if someControl is undefined or null?
As long you do not attach a required Validator to a formControl it is considered optional in the form. Your form will not have any error for such fields since there is no required Validator attached to them. It is attached like this:
firstName: ['', Validators.required],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With