Angular Material 组件不起作用:“mat-option"不是已知元素 [英] Angular Material component not working: 'mat-option' is not a known element
本文介绍了Angular Material 组件不起作用:“mat-option"不是已知元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试添加角度材料组件.但该组件无法正常工作.那个错误说
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:
// ...
我认为错误来自 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 { }
推荐答案
你需要导入 MatSelectModule
因为 mat-option
是在这个模块里面声明的,并且把这个添加到AppModule
导入
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 { }
这篇关于Angular Material 组件不起作用:“mat-option"不是已知元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文