Skip to content

updated Creating a Custom Form Field doc ngControl section #9855

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 3 commits into from
Feb 9, 2018
Merged

updated Creating a Custom Form Field doc ngControl section #9855

merged 3 commits into from
Feb 9, 2018

Conversation

rellis-of-rhindleton
Copy link

If the component already implements ControlValueAccessor, injecting NgControl in the constructor (as described in the docs) may fail. Added an alternate approach to get past this problem.

…lect errors injecting NgControl

If the component already implements ControlValueAccessor, injecting NgControl in the constructor (as described in the docs) may fail. Added an alternate way.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address on your commit. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot. The email used to register you as an authorized contributor must be the email used for the Git commit.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot googlebot added the cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla label Feb 9, 2018
@rellis-of-rhindleton
Copy link
Author

Signed CLA.

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Feb 9, 2018
// ...

ngAfterViewInit() {
this.ngControl = this._injector.get(NgControl);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that this is the proper way to handle it either. Instead of providing the NG_VALUE_ACCESSOR, you can set the accessor the same way we do for mat-select. See https://github.com/angular/material2/blob/master/src/lib/select/select.ts#L489

Choose a reason for hiding this comment

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

Ah, I saw two approaches and picked the other one. Not knowing enough about Angular internals it’s hard to say which is better. I’ll revise.

@rellis-of-rhindleton
Copy link
Author

Revision added.

@jelbourn jelbourn requested a review from mmalerba February 9, 2018 17:13
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

@rellis-of-rhindleton Awesome, thanks for this! one small wording request and then I'll mark it as ready to merge

```

Note that if your component implements `ControlValueAccessor`, it may already be set up to provide `NG_VALUE_ACCESSOR` (in the `providers` part of the component's decorator, or possibly in a module declaration). If so you may get a *cannot instantiate cyclic dependency* error.

To resolve this, remove the `NG_VALUE_ACCESSOR` and instead set the value accessor directly:
Copy link
Contributor

Choose a reason for hiding this comment

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

...remove the NG_VALUE_ACCESSOR provider and...

@rellis-of-rhindleton
Copy link
Author

Good call, done.

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Feb 9, 2018
@mmalerba mmalerba merged commit 98daab3 into angular:master Feb 9, 2018
mmalerba pushed a commit that referenced this pull request Feb 11, 2018
* Creating a custom form field docs -- updated ngControl section to reflect errors injecting NgControl

If the component already implements ControlValueAccessor, injecting NgControl in the constructor (as described in the docs) may fail. Added an alternate way.

* Update creating-a-custom-form-field-control.md

* added word "provider" for clarity
@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 Sep 8, 2019
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants