我没有使用打字稿而是使用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');
}
}
Run Code Online (Sandbox Code Playgroud)