Change detection does not trigger when the formgroup values change

前端 未结 4 657
我在风中等你
我在风中等你 2021-01-11 19:12

I have created a simple example to demonstrate a weird issue I\'m facing.

Stackblitz - https://stackblitz.com/edit/angular-change-detection-form-group

I hav

4条回答
  •  粉色の甜心
    2021-01-11 19:45

    I found a workaround to this problem although I am not sure if this is the ideal solution.

    We can listen to the form group value changes and then trigger change detection in the input component

    this.form.valueChanges.subscribe( () => {
      this.cdr.detectChanges()
    });
    

    This way it updates the label values as well along with the inputs.

    Here is the solution:

    https://stackblitz.com/edit/angular-change-detection-form-group-value-change-issue-resolved

    I'm not sure if it's a bug from Angular but happy that I figured out some workaround :)

提交回复
热议问题