-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs: implement ControlValueAccessor in the code snippet #21905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some more snippets like this one after the ngControl
section. Should it be added there as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, makes sense.
`this` should implement `ControlValueAccessor` because `valueAccessor` has type `ControlValueAccessor | null` in the `this.ngControl.valueAccessor = this;` (cherry picked from commit 8726e57)
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
this
should implementControlValueAccessor
becausevalueAccessor
has typeControlValueAccessor | null
in the
this.ngControl.valueAccessor = this;
(line 216)Affected URL: https://material.angular.io/guide/creating-a-custom-form-field-control#ngcontrol