docs: implement ControlValueAccessor in the code snippet #21905
Conversation
`this` should implement `ControlValueAccessor` because `valueAccessor` has type `ControlValueAccessor | null` in the `this.ngControl.valueAccessor = this;`
| @@ -202,7 +202,7 @@ To resolve this, remove the `NG_VALUE_ACCESSOR` provider and instead set the val | |||
| // }, | |||
| ], | |||
| }) | |||
| export class MyTelInput implements MatFormFieldControl<MyTel> { | |||
| export class MyTelInput implements MatFormFieldControl<MyTel>, ControlValueAccessor { | |||
crisbeto
Feb 15, 2021
Member
There are some more snippets like this one after the ngControl section. Should it be added there as well?
There are some more snippets like this one after the ngControl section. Should it be added there as well?
AlexElin
Feb 15, 2021
Author
Contributor
I've found only one snippet after the ngControl section. It's improving-accessibility.
Probably, there's no need to add ControlValueAccessor there becasue forms are not main subject of that section.
I've found only one snippet after the ngControl section. It's improving-accessibility.
Probably, there's no need to add ControlValueAccessor there becasue forms are not main subject of that section.
crisbeto
Feb 15, 2021
Member
I guess the way I've been reading the guide is that the sections build on top of each other so it would be weird if one snippet had it and the other one didn't.
I guess the way I've been reading the guide is that the sections build on top of each other so it would be weird if one snippet had it and the other one didn't.
AlexElin
Feb 15, 2021
Author
Contributor
I've reread the docs and found very important point in the errorState section:
Since we're not using an NgControl in this example, we don't need to do anything ...
So I think there's no need to add ControlValueAccessor in other sections except ngControl
What do you think?
I've reread the docs and found very important point in the errorState section:
Since we're not using an NgControl in this example, we don't need to do anything ...
So I think there's no need to add ControlValueAccessor in other sections except ngControl
What do you think?
crisbeto
Feb 15, 2021
Member
Sure, makes sense.
Sure, makes sense.
8726e57
into
angular:master
`this` should implement `ControlValueAccessor` because `valueAccessor` has type `ControlValueAccessor | null` in the `this.ngControl.valueAccessor = this;` (cherry picked from commit 8726e57)
thisshould implementControlValueAccessorbecausevalueAccessorhas typeControlValueAccessor | nullin the
this.ngControl.valueAccessor = this;(line 216)Affected URL: https://material.angular.io/guide/creating-a-custom-form-field-control#ngcontrol