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

后端 未结 3 1504
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 10:58

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\         


        
相关标签:
3条回答
  • 2021-01-17 11:27

    You need to import MatSelectModule in AppModule.ts

    import {MatButtonModule, MatCheckboxModule, MatSelectModule} from '@angular/material';
    
    imports: [
        BrowserModule,
        AppRoutingModule,
        HttpClientModule,
        MatButtonModule,
        MatCheckboxModule,
        MatFormFieldModule,
        MatSelectModule
      ]
    
    0 讨论(0)
  • 2021-01-17 11:34

    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 { }
    
    0 讨论(0)
  • 2021-01-17 11:44

    You need to import MatSelectModule,

    imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        MaterialModule,
        MatSelectModule,
        //..Other modules here
    ],
    
    0 讨论(0)
提交回复
热议问题