Access valid value of custom form control

后端 未结 2 530
无人共我
无人共我 2021-02-01 09:55

I created custom component representing password form control (code below is simplified).

PasswordComponent (html)

2条回答
  •  醉酒成梦
    2021-02-01 10:18

    One more way to solve this problem is to Remove the NG_VALUE_ACCESSOR from the provider and just inject NgControl. Using the NgControl instance the component will be registered as ValueAccessor.

    constructor(
    ..., 
    @Optional() @Self() public ngControl: NgControl,
    ...,
    ) {
    // Setting the value accessor directly (instead of using
    // the providers) to avoid running into a circular import.
    if (this.ngControl != null) { this.ngControl.valueAccessor = this; }
    }
    

提交回复
热议问题