angular - Angular Dialog:找不到 DialogModule 的组件工厂。
问题描述
尝试使用角度 6 中的特征模型进行对话。但我收到此错误:
没有找到 DialogModule 的组件工厂。你把它添加到@NgModule.entryComponents 了吗?
每个人都在说要使用
entryComponents:[DialogComponent]
我已经在做。还尝试在功能模块中使用它但没有成功。以下是我认为必要和简化的文件:
app.module.ts
import { DialogModule } from './components/dialog/dialog.module';
import { DialogComponent } from './components/dialog/dialog.component';
...
// AoT requires an exported function for factories
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
}
@NgModule({
declarations: [..., AppComponent],
imports: [DialogModule],
entryComponents: [DialogComponent],
providers: [..., MatDialogModule],
bootstrap: [AppComponent]
})
export class AppModule {}
对话框.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DialogComponent } from './dialog.component';
...
@NgModule({
imports: [
CommonModule
],
declarations: [..., DialogComponent],
exports: [DialogComponent]
})
export class DialogModule {
...
}
some-other.component.ts
import { DialogModule } from '../../components/dialog/dialog.module';
...
@Component({
...
})
export class LanguageButtonComponent implements OnInit {
constructor(private languageService : LanguageService,
private dialog: MatDialog,) {
}
// activated from button
openDialog() {
this.dialog.open(DialogModule);
}
}
如何摆脱错误?
解决方案
你必须把你的DialogComponent
inentryComponents
而DialogModule
不是 in AppModule
:
- 放置
entryComponents
在正确的模块中
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DialogComponent } from './dialog.component';
...
@NgModule({
imports: [
CommonModule
],
declarations: [DialogComponent],
exports: [DialogComponent],
entryComponents: [DialogComponent],
})
export class DialogModule {
...
}
entryComponents
从中删除AppModule
推荐阅读
- vba - 从 Excel 单元格中的地址创建 PDF
- r - Rmarkdown 无法识别 pdf 中的乳胶换行符
- python - 多指数熔体_枢轴
- javascript - 在选项卡中一次退出脚本或运行 Tamerpmonkey Userscript 的方法?
- styled-components - 使用样式化组件条件渲染 SVG
- codenameone - 为移动应用程序设置网络呼叫超时
- c++ - C++:是否可以编写一个将不同类型的元素附加到变体数组的函数?
- c# - 在 Devexpress Gridcontrol 绑定中使用 nameof 指定 FieldName
- php - 文件导出到空白 excel - PHP
- javascript - 将引导程序下拉默认文本替换为所选选项的文本