如果使用loadAsRoot()
你需要明確地調用變化檢測像
function onYourComponentDispose() {
}
let el = this.elementRef
let reuseInjectorOrCreateNewOne = this.injector;
this.componentLoader.loadAsRoot(YourComponent, this.elementRef, reuseInjectorOrCreateNewOne, onYourComponentDispose)
.then((compRef: ComponentRef) => {
// manually include Inputs
compRef.instance['myInputValue'] = {res: 'randomDataFromParent'};
// manually include Outputs
compRef.instance['myOutputValue'].subscribe(this.parentObserver)
// trigger change detection
cmpRef.location.internalElement.parentView.changeDetector.ref.detectChanges()
// always return in a promise
return compRef
});
參見https://github.com/angular/angular/issues/6370#issuecomment-193896657
我現在明白爲什麼是負荷根有問題的,它引用了「ID = someid」,並loadIntoLocation是使用「#someid」,它是完全不同的參考,它打破。好。 loadIntoLocation作爲未來的默認值;)。謝謝你,岡瑟。幾分鐘後會接受答案... – Teddy