angular - 模块“DynamicHtmlModule”导入的意外值“IonicModule”。请添加@NgModule 注释
问题描述
我试图在抛出后追踪这段代码:
Unexpected value 'IonicModule' imported by the module 'DynamicHtmlModule'. Please add a @NgModule annotation.
该代码根据动态使用的模块集通过模板创建动态 HTML 组件。该代码的工作原理如下:
createAndCompileComponent(alertCtrl: AlertController, template: string, componentClass: any, extraImports: any[] = []): Promise<ComponentFactory<any>> {
// Create the component using the template and the class.
const component = Component({
template: template
})
(componentClass);
const imports = this.IMPORTS.concat(extraImports);
// Now create the module containing the component.
@NgModule({imports: imports, declarations: [component]})
class DynamicHtmlModule { }
try {
// Compile the module and the component.
return this.compiler.compileModuleAndAllComponentsAsync(DynamicHtmlModule).then((factories) => {
// Do some stuff
});
} catch (ex) {
let message = 'Template has some errors and cannot be displayed.';
return Promise.reject({message: message, debuginfo: ex});
}
}
依赖模块的“imports”数组由两部分组成:
静态部分:
protected IMPORTS = [ IonicModule, TranslateModule.forChild(), // 其他一些本地创建的模块];
动态部分,这是
extraImports
奇怪的部分,当我在控制台中记录这个数组时,它是空的!!,所以我想也许这个特定的 HtmlComponent 不需要额外的,所以我尝试用一个硬替换它编码空数组,令人惊讶的是它甚至在达到原始错误之前就中断了。
解决方案
推荐阅读
- echo - KSH:处理命令时显示等待消息
- c# - C#异步取消异常
- php - 使用Ajax时如何为A标签参数添加值
- python - 一天的 Apache Beam 窗口化
- r - 将 DNAStringSet 转换为 R 中的元素列表?(seq[[1]][["seq"]] 中的错误:R 中的下标越界)
- python - 如何使用 Selenium 和 Python 查找与用户输入相关的元素?
- wordpress - WordPress:“全部”过滤器在管理员列表页面上不起作用?
- c++ - 如何声明已在静态库中定义的类?
- php - 具有数据库查询的多级循环
- python - 想要一个表现得像 ABC 但也是元类的类