我想你應該在這種情況下使用動態組件創建。剛剛嘗試在你的服務或組件,哪知道,當你有渲染你的內容水木清華這樣的:
import {ComponentResolver, ComponentFactory, ComponentRef, ApplicationRef, Injector} from '@angular/core';
export class SomeServiceOrComponent {
constructor(private resolver:ComponentResolver, private injector:Injector, private appRef:ApplicationRef) {
}
renderComponent() {
return this.resolver
.resolveComponent(YourDynamicComponentClass)
.then((factory:ComponentFactory<YourDynamicComponentClass>) => {
let cmpRef:ComponentRef<YourDynamicComponentClass> =
factory.create(this.injector, null, '.infoWindowsDOMSelector');
(<any>this.appRef)._loadComponent(cmpRef);
return cmpRef;
});
}
}
,只是調用這個方法,你是否需要它。
(<any>this.appRef)._loadComponent(cmpRef)
爲RC的上一個版本的一招,但也許很快就應該解決
我是相當新的一般的角,所以請原諒我的無知。此示例是構建到現有類中嗎?還是SomeServiceOrComponent引用了用於呈現動態內容的實用程序服務? – somecallmemike
啊我得到它的工作,感謝您的幫助。我猜現在唯一的麻煩就是如何使用這種方法將數據作爲@Input從父項傳遞給新組件? – somecallmemike
得到這個工作也買添加cmpRef.instance.inputData = data;創建cmpRef後; – somecallmemike