nazanin n
nazanin n

Reputation: 131

mat-form-field' is not a known element in angular

i am using input from angular material but i get this error **ERROR in src/app/modules/posts/posts.component.html:2:5 - error NG8001: 'mat-form-field' is not a known element: 1. If 'mat-form-field' is an Angular component, then verify that it is part of this module. 2. If 'mat-form-field' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

this is my html code

<form class="example-form">
    <mat-form-field class="example-full-width">
     Favorite food
      <input matInput >
    </mat-form-field>


  </form>

this is my app module

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { DefaultModule } from './layouts/default/default.module';
import { MatTableModule } from '@angular/material/table';
import { HttpClientModule } from '@angular/common/http';
import {UserInfoService} from './services/user-info.service'
import {MatCardModule} from '@angular/material/card';
import {MatDialogModule} from '@angular/material/dialog';
import { PostsComponent } from './modules/posts/posts.component';
import {  MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';

@NgModule({
  declarations: [
    AppComponent,



  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    DefaultModule,
    MatTableModule,
    HttpClientModule,
    MatCardModule,
    MatDialogModule,
    MatFormFieldModule,
    MatInputModule
  ],
  exports: [

    MatFormFieldModule,
    MatInputModule,

  ],
  providers: [UserInfoService],
  bootstrap: [AppComponent],
  entryComponents:[PostsComponent]
})
export class AppModule { }

i can not find the right solution for this can you help me?

Upvotes: 3

Views: 9008

Answers (1)

Nitika
Nitika

Reputation: 479

Add FormsModule, ReactiveFormsModule, to imports section. Remove both exports elements.

Upvotes: 4

Related Questions