UI not get updated if I use same formcontrol in parent child

Viewed 902

I am facing a scenario in which I am using a formGroup in parent component and child component. and I have placed same form control in parent and child but when I update value in parent, formgroup gets updated but value of control placed on child component do not get updated and vice versa. I have made a DEMO Please guild me what I have to do if I want both parent and child component get updated ui if value is changed either from parent or from child.

1 Answers

as discuses on this github issue this is not wrong even if you in the same component if two input with the same formControlName only the one you are change will change.

there is a workaround on the child component

app-child

ngOnInit(){
  this.address.valueChanges.subscribe(val =>{
    this.address.patchValue(val,{emitEvent:false})
  })
}

any change from parent or child will trigger form.patchValue and that will update the UI

demo

Related