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.

Error: mat-form-field must contain a MatFormFieldControl

See original GitHub issue

Describe the bug Receive the error when ng-select is wrapped inside a mat-form-field element

To Reproduce Steps to reproduce the behavior:

  1. Create a Reactive Form
  2. Wrap ng-select component inside mat-form-field element
  3. Check console to see error

Expected behavior ng-select should not break

Code

<mat-grid-tile [colspan]=1 [rowspan]=1>
    <mat-form-field>
    <ng-select matInput placeholder="Select country" #countrySelect [items]="country$" [selectOnTab]="true"
        bindValue="id" labelForId="name" [formControl]="countryFormControl">
    </ng-select>
    </mat-form-field>
</mat-grid-tile>

Additional context The problem seems to be ng-select not having an matInput directive which is shared across mat-form-field chlidren.

Have added the Material Modules: Form, Input, Select https://github.com/angular/material2/issues/7898

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
nzbincommented, Oct 7, 2020

@Dsupreme @kelvinlouis @davdinesh I have made a Material form field wrapper of ng-select (demo), it’s a component of Material extended library. Material Extensions: https://github.com/ng-matero/extensions

4reactions
jean-mereliscommented, Nov 16, 2018

@kelvinlouis I have created a directive to support the MatFormFieldControl. SCSS file needs a little more polishing but it works as expected. https://gist.github.com/jean-merelis/44a3ed842c24e99d38cd2f1e9249c473#file-ng-select-directive-ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

mat-form-field must contain a MatFormFieldControl
Error: mat-form-field must contain a MatFormFieldControl. This error occurs when you have not added a form field control to your form field.
Read more >
Error: mat-form-field must contain a MatFormFieldControl ...
Bug, feature request, or proposal: When doing a karma/jasmine test I get an error on the tag. This in combination with a.
Read more >
mat-form-field must contain a MatFormFieldControl - Elite Corner
This error usually occurs in 4 scenarios when we missed to import module for specific component. Problem 1: MatInputModule or MatFormFieldModule ...
Read more >
mat-form-field must contain a MatFormFieldControl
mat-form-field must contain a MatFormFieldControl. I got an error while I was trying to add Angular material mat-form-field control. Here is how ...
Read more >
mat-form-field must contain a MatFormFieldControl - Edureka
I am getting this error: "mat-form-field must contain a MatFormFieldControl" in the console. How can I fix this?
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