I have this form:
public profileSettingsGroup = new FormGroup({
firstName: new FormControl('Jonathon', Validators.required)
})
I have this method:
setControlValue(control: string, value: string){
this.profileSettingsGroup.patchValue({
control: value
});
}
I have this map:
for (let control in this.profileSettingsGroup.controls) {
this.map.set(control, this.camelCase(control));
}
I'm attempting to update the controls in the form via a variable, but angular seems to not allow me to dynamically name form controls. It's taking control
as an actual control named: "control". Can I do what I want in angular?
You need brackets around control. See computed property names over at MDN
setControlValue(control: string, value: string){
this.profileSettingsGroup.patchValue({
[control]: value
});
}
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