【发布时间】:2017-02-10 14:39:04
【问题描述】:
我需要在 Angular 2 中为 dart 添加一个“外部”对象到依赖注入。 “外部”的意思是,它的构造函数上没有 @Injectable 注释,因为它来自外部库。
所以我想,我可以像这样在@Component 注释中将此依赖项添加到 Angular 2 提供程序列表中:
@Component(
selector: "app-component",
templateUrl: "app_component.html",
directives: const [AddButton, SettingsButton],
providers: const [const Provider(EventBus, useValue: new EventBus())]
)
问题是这个列表必须是一个 const 表达式。因此 Provider 必须是 const 并且 `new EventBus()' 不被支持为非常量表达式。
搜索文档没有产生结果。 我该怎么做?
【问题讨论】: