我正在尝试构建modals仅依赖于CDK. 模态是通过服务打开的,我通过entryComponent以模态渲染它。
这是示例:https ://stackblitz.com/edit/angular-ofzpks?file=src%2Fapp%2Fmodal.component.ts
在模态本身中,我正在使用工厂创建组件:
const compRef = this.componentFactoryResolver.resolveComponentFactory<any>(this.modalContentComponent);
const componentRef = this.modalContainer.createComponent(compRef);
我有两个问题:
- 我必须
componentRef.instance.ngOnInit();手动触发 - 我将一些数据传递给该组件:
componentRef.instance.name = this.data.name;但组件从不呈现它