【发布时间】:2016-11-16 13:59:34
【问题描述】:
我可以使用这个方法创建动态组件:
public addItem<T extends WidgetComponent>(ngItem: {new(): T}): T {
let factory = this._componentFactoryResolver.resolveComponentFactory(ngItem);
const ref = this._viewCntRef.createComponent(factory);
const newItem: T = ref.instance as T;
...
return newItem;
}
然后这样称呼它:
const ref: MyWidgetComponent = this.dashboard.addItem<MyWidgetComponent>(MyWidgetComponent);
但是 typescript 给我这个编译错误:
app.component.ts:45:35
Untyped function calls may not accept type arguments.
我尝试用Type<T> 替换{new(): T},但我有同样的错误:app.component.ts:45:35
Untyped function calls may not accept type arguments.
这里的正确定义是什么?因为代码很好用……
编辑:这里是完整的代码,如果你想看到它https://github.com/jaumard/ng2-dashboard/blob/master/components/dashboard/dashboard.component.ts#L99
【问题讨论】:
标签: angularjs angular typescript compilation angular2-components