typescript Angular Material 组件不起作用:“mat-option”不是已知元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52052895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular Material component not working: 'mat-option' is not a known element
提问by gihankumara
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
:
我认为错误来自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 { }
回答by Suren Srapyan
You need to import MatSelectModule
cause mat-option
are declared inside this module and add this into the AppModule
imports
您需要在此模块中声明导入MatSelectModule
原因mat-option
并将其添加到AppModule
导入中
import { ..., MatSelectModule, ... } from '@angular/material';
@NgModule({
imports: [ ..., MatSelectModule, ...]
})
export class AppModule { }
回答by Sajeetharan
You need to import MatSelectModule
,
你需要导入MatSelectModule
,
imports: [
BrowserModule,
FormsModule,
HttpModule,
MaterialModule,
MatSelectModule,
//..Other modules here
],
回答by Ashok
You need to import MatSelectModulein AppModule.ts
您需要导入MatSelectModule在AppModule.ts
import {MatButtonModule, MatCheckboxModule, MatSelectModule} from '@angular/material';
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
MatButtonModule,
MatCheckboxModule,
MatFormFieldModule,
MatSelectModule
]