Reputation: 21
Is there a way to get the value of a formControl by passing the control name as a function argument?
destructCityAndStreetFromObject(type: string) {
let form: FormGroup = (this.section2Form.controls.formControlBuilderinputs as FormGroup)
let Val = form.controls.`${type}`.value.value;
}
Upvotes: 0
Views: 991
Reputation: 465
function destructCityAndStreetFromObject(type: string) {
const form = (this.section2Form.controls.formControlBuilderinputs as FormGroup)
const ctrlType = form.controls[type];
if(ctrlType){
const {value:{value: Val}} = ctrlType;
}
}
Upvotes: 3
Reputation: 599
let ctrlName = "myControl";
form.controls[ctrlName].value = ctrlName;
Upvotes: 0