Angular Material component not working: 'mat-option' is not a known element
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 { }
Actually you also need to add MatOptionModule
not just MatSelectModule
.
imports: [
...
MatSelectModule,
MatOptionModule,
...
],
Otherwise you may encounter problems when setting the value
of your mat-option
.
I amazed that none of the answers given by the user is correct, how I knew that? is because i faced the same problem by myself.
the solution is to import import {MatSelectModule} from '@angular/material/select';
and write in import MatSelectModule
You need to import MatSelectModule
,
imports: [
BrowserModule,
FormsModule,
HttpModule,
MaterialModule,
MatSelectModule,
//..Other modules here
],