如何使用mat-tab?mat-tab 不是已知元素错误 [英] How to use mat-tab? mat-tab is not a known element error

查看:64
本文介绍了如何使用mat-tab?mat-tab 不是已知元素错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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> -->

推荐答案

在你的 module.ts 文件中添加 import 并将其添加到导入中(如果你使用多个 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆