#Two-way data binding

1 messages · Page 1 of 1 (latest)

sleek bone
#

new to angular, how do i achieve two-way data binding on form builder reactive forms? ngModel doesn't work like it does in template-driven forms

cobalt ridge
#

The 2-way data binding equivalent would probably be to observe the form value to see when the data in the form changed and to set the value (with emit false) when you want to change the form data

#
// observable with the form data
formGroup.valueChanges.subscribe(...);
// update the form data
formGroup.setValue(formData, { emitEvent: false });
#

(might not need the emitEvent false but if you don't have it you're likely to make some kind of infinite loop)

tardy ingot
#

take a look at formControlName directive used by the reactive forms api instead of using ngModel directive