angular - 角度模块中的条件提供程序引发 AOT 错误
问题描述
仅当浏览器是 IE 时,我才想将提供程序推送到我的提供程序列表中。
我试过了
const IE = detectIE();
providers: [abcService,
xyzService,
(IE) ? [{provide: EVENT_MANAGER_PLUGINS,
useClass: IeInputEventManagerService,
deps: [DOCUMENT],
multi: true
}] : [],
上面的代码抛出 AOT 错误,说装饰器中不允许使用符号。我也试过如下
const IE = detectIE();
const tempProviders: Array<any> = [
abcService,
xyzService];
if(IE) {
tempProviders.push({provide: EVENT_MANAGER_PLUGINS,
useClass: IeInputEventManagerService,
deps: [DOCUMENT],
multi: true
});
}
@NgModule -> continues here
在上述情况下,提供者永远不会被推送或永远不会被激活。我该如何解决这个问题?
解决方案
推荐阅读
- python - python中的实例方法和@classmethod和@staticmethod有什么区别?
- sql - 如何在SSRS中获得2次之间的差异
- python - 如何快速迭代不同长度的多个列表
- django-oscar - Django Oscar模板覆盖不起作用
- javascript - 如何使用 Node JS 打开 PDF 文件?
- python - 正则表达式:匹配任意单词前面的任意数量的括号
- php - 调试模式在不同环境下的 laravel 中不起作用
- javascript - Webpack 文件加载器,如何使用 outputPath 函数
- elasticsearch - 来自 Lambda 的 AppSync 映射响应从 ElasticSearch 获取结果
- r-markdown - 在 html 中使用 pdf 参数调用 knitr::include_graphics() 时出现“无法加载插件”