Angular - controlValueAccessor method writeValue() not being called

后端 未结 2 1855
旧巷少年郎
旧巷少年郎 2020-12-19 17:20

Angular Version: 6.1

I\'m trying to implement a custom control using what Kara Erickson is calling a Composite ControlValueAccessor as shown in the presentation, An

2条回答
  •  不知归路
    2020-12-19 17:44

    writeValue is called when you are changing control value (eg by setting backing ngModel property or controll value) not by user input.

    https://stackblitz.com/edit/angular-hu2bfs?file=src/app/app.module.ts

    I have removed errors caused by misused ngModel

    As you can see, if you type into extra input new value and push the button, writeValue is called.

    to wrap it up - writeValue is called when controller changes model value, and writeValue purpose is to do required stuff to reflect model changes by custom control.

提交回复
热议问题