Is there a way to access the NgModel
of a FormControl
retrieved from the NgForm.controls
object within its parent form, or directly from the form itself?
Upon form submission, I pass the form as a parameter to a custom function:
<form #myForm="ngForm" name="myForm" (ngSubmit)="myFunc(myForm)">
<input type="text" name="myInput" ngModel #myInput="ngModel">
</form>
myFunc(form) {
form.controls // Retrieves {[key: string]: FormControl}
}
I aim to modify properties of the controls fetched from the form (as NgModel
s) and use them in the template like this:
{{ myInput.myProp }}
Rather than:
{{ myInput.control.myProp }}
The main objective is to assign a custom property to each NgModel
in a form upon submission, without having to extract that property from its underlying control. Is this achievable or am I approaching it incorrectly?