Angular Material component not working: 'mat-option' is not a known element

gihankumara picture gihankumara · Aug 28, 2018 · Viewed 21.1k times · Source

I am trying to add angular material component. but the component did not work properly. that error said

Uncaught Error: Template parse errors: 'mat-option' is not a known element:
// ...

I think the error comes from app.module.ts:

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

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { SidebarComponent } from './sidebar/sidebar.component';
import { PostsComponent } from './posts/posts.component';
import { UsersComponent } from './users/users.component';
import { DetailsComponent } from './details/details.component';
import { HttpClientModule } from '@angular/common/http';
import { FooterComponent } from './footer/footer.component'; 
import {MatButtonModule, MatCheckboxModule} from '@angular/material';
import {MatFormFieldModule} from '@angular/material/form-field';
import { MyFormComponent } from './my-form/my-form.component';
@NgModule({
  declarations: [
    AppComponent,
    SidebarComponent,
    PostsComponent,
    UsersComponent,
    DetailsComponent,
    FooterComponent, MyFormComponent
  ],
  imports: [
    BrowserModule, AppRoutingModule,HttpClientModule,MatButtonModule, MatCheckboxModule,MatFormFieldModule
  ]
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Answer

Suren Srapyan picture Suren Srapyan · Aug 28, 2018

You need to import MatSelectModule cause mat-option are declared inside this module and add this into the AppModule imports

import { ..., MatSelectModule, ... } from '@angular/material';

@NgModule({
   imports: [ ..., MatSelectModule, ...]
})
export class AppModule { }