javascript - 无法使用 Material 选项卡

标签 javascript angular typescript angular-material

我很高兴在 https://material.angular.io/components/tabs/api#MatTab 找到有关 Material 选项卡的内容。并很高兴在我的项目中使用它。

我按照建议添加了导入,但它不起作用。我发现:can not find module "@angular/material"并导入这些内容并让导入在我的 maintab 组件上运行。

但是 mat-tab 链接仍然不起作用。这是我的 maintab.component.ts

import { Component, OnInit } from '@angular/core';
import {MatTabsModule} from '@angular/material';

@Component({
  selector: 'app-maintab',
  templateUrl: './maintab.component.html',
  styleUrls: ['./maintab.component.css']
})
export class MaintabComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

这是我的 maintab.component.html

<mat-tab-group>
  <mat-tab label="One">
    <h1>Some tab content</h1>
    <p>...</p>
  </mat-tab>
  <mat-tab label="Two">
    <h1>Some more tab content</h1>
    <p>...</p>
  </mat-tab>
</mat-tab-group>

我仍然遇到这些类型的错误:

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. ("<mat-tab-group>
  [ERROR ->]<mat-tab label="One">
    <h1>Some tab content</h1>
    <p>...</p>
"): ng:///AppModule/MaintabComponent.html@1:2
'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. ("
    <p>...</p>
  </mat-tab>

我只是不知道下一步该做什么。

最佳答案

问题是您正在将模块导入到组件中。您需要将 MatTabsModule 导入到 AppModule 中,并将其作为提供程序包含在内。只要您的 MaintabComponent 在您的应用程序模块中声明,这就会起作用。

如果您的 MaintabComponent 未在您的 AppModule 中声明,您需要导入 MatTabsModule 并在声明它的模块中提供AppModule 的。

(如果您仍然遇到问题,请包含声明此组件的模块的代码以获得进一步帮助)

关于javascript - 无法使用 Material 选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48358058/

相关文章:

javascript - 复杂 else if 梯子的替代方案

javascript - eslint 为什么我的插件显示未找到规则定义?

javascript - Angular 5 - 动态行添加清除表中的选择

javascript - JQuery 未传递 SELECT 表单参数

javascript - 使用 AngularJS 在新窗口中打开链接

PHP构造的JavaScript onClick函数在ajax响应返回时不起作用

javascript - 带有Angular的ASP.NET Core上的级联下拉列表

typescript - 无法将功能部署到 Firebase

javascript - 订阅更改,但需要查看使用服务的位置的变量?

javascript - jquery 动画然后停止