【发布时间】:2016-01-07 04:55:51
【问题描述】:
我不是使用 typescript 而是 ES6 和 angular2 alpha39 来动态加载组件。以下代码类似于我在我的应用程序中的代码。我注意到的是 angular2 没有创建 DynamicComponentLoader 的实例,也没有创建 ElementRef 并注入到构造函数中。它们是未定义的。
如何使用 ES6 和 angular2 alpha39 进行 DynamicComponentLoader 的注入?
import {Component, View, Inject, DynamicComponentLoader, ElementRef } from 'angular2/angular2'
@Component({
selector: 'dc',
bindings: [ DynamicComponentLoader ]
})
@View({
template: '<b>Some template</b>'
})
class DynamicComponent {}
@Component({
selector: 'my-app'
})
@View({
template: '<div #container></div>'
})
@Inject(DynamicComponentLoader)
@Inject(ElementRef)
export class App {
constructor(
dynamicComponentLoader,
elementRef
) {
dynamicComponentLoader.loadIntoLocation(DynamicComponent, elementRef, 'container');
}
}
【问题讨论】:
标签: dependency-injection angular