javascript - Angular Material:“在'./material/material.module'中找不到导出'MaterialComponents'
问题描述
我是 Angular 的新手,在导出材质模块时遇到了一些问题。这是错误:
(编译失败。)./src/app/app.module.ts 17:12-30“在'./material/material.module'中找不到导出'MaterialComponents'
这是材质模块:
import { NgModule } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
const MaterialComponents = [
MatButtonModule
];
@NgModule({
exports: [MaterialComponents],
imports: [MaterialComponents],
})
export class MaterialModule { }
应用模块:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MaterialComponents } from './material/material.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MaterialComponents
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
解决方案
改正为MaterialModule
import { MaterialModule } from './material/material.module';
imports: [
BrowserModule,
BrowserAnimationsModule,
MaterialModule //< -- HERE
],
另外,请注意,import
如果export
您想创建一个通用共享模块来整合所有其他模块,则modules
不需要这样做:
@NgModule({
exports: [MatButtonModule, OtherMatModules...],
imports: [],
})
export class MaterialModule { }
虽然,错误来了,因为你没有把export
关键字放在前面
export const MaterialComponents = [
MatButtonModule
];
即使你把出口,你最终会得到错误,所以只需使用我上面的建议。用你传递的array
价值观array
在你的情况下,下面
@NgModule({
exports: [MaterialComponents],
imports: [MaterialComponents],
})
相当于:
@NgModule({
exports: [[MatButtonModule]],
imports: [[MatButtonModule]],
})
这是嵌套数组,并且 angular 的语法错误
推荐阅读
- html - 如何删除导航栏元素底部和右侧的那些小间隙?
- django - ValidationError: ["'02/12/2020' 值的日期格式无效。它必须是 YYYY-MM-DD 格式。"]
- java - 将时间戳转换为字符串给出字符值
- c# - 使用 C# webrequests 时如何在 Wireshark 中解密 TLS 通信
- css - 表示网格布局的最佳方式
- android - 相同的数字为 mobile_number 字符串提供输出
- sql-server - 有没有人使用动态列排列将行参数发送到 MS-SQL Server 中的存储过程的解决方案?
- arrays - 循环创建相同长度字符串的数组
- python - 从相对路径运行 Pycharm
- reactjs - 相机在 android ionic react 应用程序中不起作用