嗨,我正在尝试通过ComponentFactoryResolver呈现组件视图并放到DOM中,但是属性在呈现时没有定义,在这种情况下该怎么办?
构成部分的财产:
@Input('productId') productId;创建视图并将数据传递给属性:
const componentRef: any = this.componentFactoryResolver
.resolveComponentFactory(component)
.create(this.injector);
componentRef.instance.productId = data.productId;在模板中
<div>{{ productId }}</div>productId未定义
发布于 2018-02-28 10:25:29
打电话
componentRef.changeDetectorRef.detectChanges();修改属性以调用更改检测之后。
另见https://angular.io/api/core/ComponentRef#changeDetectorRef
https://stackoverflow.com/questions/49027190
复制相似问题