如何使用mat-tab?mat-tab不是已知的元素错误 [英] How to use mat-tab? mat-tab is not a known element error
问题描述
我正在尝试使用 mat-tab
.我在html中添加了以下代码
I am trying to use mat-tab
. I have added the below code in html
<mat-tab-group>
<mat-tab label="Tab 1"> <app-latest-article></app-latest-article></mat-tab>
<mat-tab label="Tab 2"> <app-trending-article></app-trending-article> </mat-tab>
</mat-tab-group>
在ts文件中
import {MatTabsModule} from '@angular/material/tabs';
我遇到错误
未捕获的错误:模板解析错误:
未知的"mat-tab"元素:
1.如果'mat-tab'是Angular组件,则请验证它是否属于此模块.
2.如果"mat-tab"是Web组件,则将"CUSTOM_ELEMENTS_SCHEMA"添加到该组件的"@ NgModule.schemas"以禁止显示此消息.("
</ngx-tabset>->
Uncaught Error: Template parse errors:
'mat-tab' is not a known element:
1. If 'mat-tab' is an Angular component, then verify that it is part of this module.
2. If 'mat-tab' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
</ngx-tabset> -->
推荐答案
在import.module文件中添加导入,并将其添加到导入(如果使用多个module.ts文件,则将其添加到负责您的组件).
Add the import in your module.ts file and add it to imports (if you use several module.ts files, add it in the one which is responsible for your component).
import { MatTabsModule } from '@angular/material';
@NgModule({
imports: [
...
MatTabsModule,
...
],
declarations: [
...
],
providers: []
})
export class AppModule {}
这篇关于如何使用mat-tab?mat-tab不是已知的元素错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!