相关疑难解决方法(0)

如何在ES6中使用angular2 DynamicComponentLoader?

没有使用打字稿而是使用ES6和angular2 alpha39动态加载组件.以下代码与我在我的应用程序中的代码类似.我注意到的是angular2不会创建DynamicComponentLoaderElementRef的实例并注入构造函数.他们是未定义的.

如何使用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)

dependency-injection angular

4
推荐指数
1
解决办法
4771
查看次数

标签 统计

angular ×1

dependency-injection ×1