question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot create a custom MatFormFieldControl that implement ControlValueAccessor

See original GitHub issue

Bug, feature request, or proposal:

Bug/Feature Request

What is the expected behavior?

The guide “Creating a custom form field control” should give an example with a custom MatFormFieldControl that implement ControlValueAccessor.

What is the current behavior?

The guide advise us to use:

constructor(..., @Optional() @Self() public ngControl: NgControl) { ... }

But it leads to a cyclic dependancy error:

ERROR Error: Uncaught (in promise): Error: Template parse errors:
Cannot instantiate cyclic dependency! NgControl

What are the steps to reproduce?

Here is a StackBlitz

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

@angular/material: 2.0.0-beta.12 @angular/core: 4.4.4 @angular/cli: 1.4.4 typescript: 2.4.2 Windows 10 64bit Chrome/Firefox/Edge

Is there anything else we should know?

I do not think so.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:23 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
tesseriscommented, Feb 1, 2018

Please provide a tutorial of a MatFormFieldControl that implements ControlValueAccessor…

8reactions
GuillaumeNurycommented, Nov 15, 2017

@ADegele Yes ! I struggled a lot with it !

Here is what I have done:

// Just add this in your constructor
if (this.ngControl) {
	this.ngControl.valueAccessor = this;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

MatFormFieldControl that implements ControlValueAccessor ...
I'm trying to create custom form control by implementing MatFormFieldControl, ControlValueAccessor and Validator interfaces.
Read more >
Cannot create a custom MatFormFieldControl that implement ...
What is the expected behavior? The guide "Creating a custom form field control" should give an example with a custom MatFormFieldControl that implement...
Read more >
Creating a custom form field control | Angular Material
The first step is to provide our new component as an implementation of the MatFormFieldControl interface that the <mat-form-field> knows how to work...
Read more >
Creating a custom form field control compatible with Reactive ...
]export class FormRichEditorComponent implements OnInit, ControlValueAccessor, MatFormFieldControl<any>) {... This sets up our component so it ...
Read more >
Angular Custom Form Controls - Complete Guide
Introduction to the ControlValueAccessor interface; Implementing the ... In order to know how to build a custom form control, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found