我通过 loadAsRoot 动态加载组件 加载组件后,组件将加载到UI中,但是即使它的属性具有值,也不会加载有界插值数据。
var componentLoadPromise = this._componentLoader.loadAsRoot(MyComponent, "#placeholder", this._injector);
return componentLoadPromise.then(myComp=> {
return new Promise<boolean>(resolve =>{
myComp["_hostElement"]["component"]["display"](compOptions, resolve);
});
});
enter code here
Component.ts
// bounded properties
public content: string;
public title: string;
public display(dialogOptions: IDialogParams, resolve: (boolean) => any){
document.onkeyup = null;
this._resolveAction = resolve;
this.setUpElements();
// here my bounded view properties are populated
this.populateViewProperties(dialogOptions);
this.wireEvents();
this._confirmElement.style.display = "block";
}
答案 0 :(得分:1)
DynamicComponentLoader
已弃用。请改用ViewContainerRef.createComponent()
DynamicComponentLoader.loadAsRoot()
仅应由bootstrap()
用于根组件,默认情况下不会进行任何更改检测。您需要手动连接变更检测以使其正常工作。
另见