The 'input' element does not recognize the property 'formControl', causing a binding issue in Angular Material Autocomplete with Angular 12

Recently, I upgraded my Angular app from version 11 to 12 along with all the dependencies, including Angular Material. However, after running 'ng serve', I encountered the following error:

Error: src/app/components/chips/chips.component.html:19:17 - error NG8002: Can't bind to 'formControl' since it isn't a known property of 'input'.

19                 [formControl]="itemCtrl"
                   ~~~~~~~~~~~~~~~~~~~~~~~~

Below are the contents of my chips.component.ts and chips.component.html files:

import {BaseComponentComponent} from '../basecomponent.component';
import {COMMA, ENTER} from '@angular/cdk/keycodes';
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
import {FormControl} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatAutocompleteModule} from '@angular/material/autocomplete';
import {MatChipInputEvent} from '@angular/material/chips';
import {Observable} from 'rxjs';
import {map, startWith} from 'rxjs/operators';
import {ChipsModel} from '../../models/chips.model';
import {MatInputModule} from '@angular/material/input';

@Component({
    selector: 'app-chips',
    templateUrl: './chips.component.html',
    styleUrls: ['./chips.component.scss']
})

export class ChipsComponent extends BaseComponentComponent {
...
}
<mat-form-field style="width: 100%;">
        <input
                #itemInput
                [formControl]="itemCtrl"
                [matAutocomplete]="auto"
                [matChipInputFor]="chipList"
                [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
                (matChipInputTokenEnd)="add($event)"
                title="">
</mat-form-field>

I have attempted various fixes suggested in similar StackOverflow posts, such as importing additional modules into a custom module that is imported in app.module.ts:

import { MatTableModule } from '@angular/material/table';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field';

@NgModule({
  imports : [
    MatInputModule,
    MatTableModule,
    FormsModule,
    ReactiveFormsModule,
    MatFormFieldModule
  ],
exports: [
    MatInputModule,
    MatTableModule,
    FormsModule,
    ReactiveFormsModule,
    MatFormFieldModule
  ]})
export class MaterialModule {}

Despite importing the ChipsComponent class in app.module.ts and declaring it within the NgModule, the error persists. Any insights on what might be causing this issue?

Answer №1

Make sure to include the MatFormFieldModule in your imports list.

import {MatFormFieldModule} from '@angular/material/form-field';

Don't forget to add it to the exports section of your MaterialModule, no need for an additional imports array.

Note: Remember to also import the MaterialModule in your main module file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error message: 'Unrecognized element' appears when using a custom Angular library component

I am currently in the process of developing a custom Angular library that will be utilized across multiple projects and eventually published to a private Verdaccio npm registry. While everything seems to work well - from rendering to building - there is o ...

Navigate to an Angular page URL using a Spring Boot REST API

I've been trying to figure out how to redirect to an Angular page from a Spring Boot API, but so far none of the methods I've tried have worked. Front end: (Angular) http://localhost:4200 Back end: (Spring Boot) http://localhost:80 ...

Alert: Circular dependency detected!

In an effort to have cleaner imports, I've set up a typescript file that exports all the components I'm using. For example: import { Comp1, Comp2, Comp3 } from index/components However, when using this approach, I encounter a warning during bu ...

Angular 2: A guide to connecting Input with model property using getter and setter functions

I'm currently developing an Angular 2 web application. The model I have created consists of a few primary properties, along with other properties that are calculated based on those primary values. For each property in my model, I have implemented get ...

Navigating the complexities of managing numerous checkboxes in React

I am a beginner with react and recently received a task to complete. The requirements are: Show multiple checkboxes. The order of checkbox names may change in the future, allowing the client to decide the display order. Display checkboxes based on their a ...

Create a TypeScript declaration file for a JavaScript dependency that contains an exported function

I am currently utilizing a dependency called is-class in my TypeScript project. Unfortunately, this particular dependency does not come with a @types definition. As a workaround, I have been using a custom .d.ts file with declare module 'is-class&apos ...

Exploring the capabilities of UIGrid in conjunction with TypeScript DefinitelyTyped has been a

I've noticed that the latest release of UI Grid (RC3) has undergone significant architectural changes compared to nggrid. I am encountering some problems with the definitelytyped files for nggrid because they are from a different version. Will there ...

How to Delete Multiple Rows from an Angular 4 Table

I have successfully figured out how to remove a single row from a table using splice method. Now, I am looking to extend this functionality to remove multiple rows at once. html <tr *ngFor="let member of members; let i = index;"> <td> ...

What is the process for configuring React on one server and springboot on a separate server?

Can you help me with the setup of the following: Web Server : I need to set up a react + typescript application using npm at Backend Server : I also need to configure a Springboot backend server at I am currently using webpack to build the react applica ...

Set an array to a JSON object as a fresh entity

My challenge involves working with an array that contains certain values. let myArray = [value1, value2]; I am looking to generate a JSON object in the format shown below: { "field": "[value1, value2]" } ...

Using Angular rxjs to efficiently make multiple API calls and merge their results in one response

After successfully making multiple calls to the same API with different payloads and merging the results into arrays of objects, I now need to mark each object in the result array for filtering purposes. For example, I want to add a property called api_id ...

angular 2 checkbox for selecting multiple items at once

Issue I have been searching for solutions to my problem with no luck. I have a table containing multiple rows, each row having a checkbox. I am trying to implement a "select all" and "deselect all" functionality for these checkboxes. Below is an example o ...

Issue with Angular FormControl/FormBuilder not selecting options in Select dropdown

I am creating a form to edit some items and include a Select element with options loaded from a database. However, even though I set up the name and description correctly using formBuilder/control in the component, the correct "category" is not being selec ...

Encountering an issue while attempting to load in Angular2 RC4: Error: XHR error (404 Not Found) during loading

I encountered an exception while the application was loading on the browser. Here are the details of the error along with the configuration files: Error Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:5 ...

Combine Angular4 for the front-end and Java for the back-end in a seamless integration

I recently followed a tutorial on integrating Angular 4 as the front-end and Java as the back-end, which you can find at this link: . The integration was successful, but I encountered a problem. Whenever I make changes to the front-end, I have to run ng bu ...

The property '.....' is missing an initializer and has not been explicitly assigned in the constructor

I want to address an issue with a similar question title that was asked 5 years ago on Stack Overflow. The problem is related to declaring a variable as an array of a specific object type in an Angular component using TypeScript 4.9. Even though I tried t ...

Guide on creating a dash-patterned line over a rectangle using PixiJS and Angular

https://i.sstatic.net/uIksi.jpg In this example, we are creating a PixiJS application that draws a solid-stroked rectangle. Unfortunately, PIXI.Graphics does not have a built-in feature to draw dashed strokes. import { Component, OnInit } from &ap ...

Ways to check the functionality of the secondary tier in the api.send method

Currently, I am testing a function that involves returning a promise and subsequently calling the same function again at a second level. However, I am facing difficulties in accessing this second level of call. Below is the function code: itemToForm = () ...

The Vercel error indicates that the file or directory '/var/task/node_modules/shiki/themes/one-dark-pro.json' does not exist

import { serialize } from 'next-mdx-remote/serialize'; import readingTime from 'reading-time'; import remarkGfm from 'remark-gfm'; import rehypeSlug from 'rehype-slug'; import rehypeAutolinkHeadings from 'rehype ...

Having trouble executing a method from a template in Angular 5?

Angular has a useful capability that almost every developer has utilized at some point: calling methods from templates. I've personally been using this feature for months without any issues. However, recently I encountered a problem. I have a menu co ...