Skip to content

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

Merged
merged 1 commit into from
Feb 16, 2021

Conversation

AlexElin
Copy link
Contributor

@AlexElin AlexElin commented Feb 15, 2021

this should implement ControlValueAccessor because
valueAccessor has type ControlValueAccessor | null
in the this.ngControl.valueAccessor = this; (line 216)

Affected URL: https://material.angular.io/guide/creating-a-custom-form-field-control#ngcontrol

`this` should implement `ControlValueAccessor` because
`valueAccessor` has type `ControlValueAccessor | null`
in the `this.ngControl.valueAccessor = this;`
@AlexElin AlexElin requested a review from jelbourn as a code owner February 15, 2021 08:41
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 15, 2021
@@ -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 {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, makes sense.

@crisbeto crisbeto added docs This issue is related to documentation action: merge The PR is ready for merge by the caretaker merge safe target: patch This PR is targeted for the next patch release labels Feb 15, 2021
@mmalerba mmalerba merged commit 8726e57 into angular:master Feb 16, 2021
mmalerba pushed a commit that referenced this pull request Feb 16, 2021
`this` should implement `ControlValueAccessor` because
`valueAccessor` has type `ControlValueAccessor | null`
in the `this.ngControl.valueAccessor = this;`

(cherry picked from commit 8726e57)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement docs This issue is related to documentation target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants