如何在实现ControlValueAccessor的Ivy中的延迟加载的Angular组件上指定formControlName?

问题描述

我的目标是延迟加载特定组件,以提高性能。我使用过this guide,它对于简单的用例非常有用。我的问题是,我尝试延迟加载的相关组件实现了ControlValueAccessor,因此被formControlName属性所消耗。延迟加载组件时如何添加它?

验证码

@ViewChild('editWysiwigContainer',{ read: ViewContainerRef })
async ngAfterViewInit() {
    // setTimeout(async () => {
    const { EddystoneWysiwigComponent } = await import(
        '../../eddystone-wysiwig/eddystone-wysiwig/eddystone-wysiwig.component'
    );
    const eddystoneWysiwigFactory = this.cfr.resolveComponentFactory(
        EddystoneWysiwigComponent
    );
    const { instance } = this.editWysiwigContainer.createComponent(
        eddystoneWysiwigFactory,null,this.injector
    );
    instance.state = 'editOnly';
    instance.updateOnBlur = true;
    instance.height = 150;
    // There is no formControlName here - how do I "fix" this?
    instance.placeholder = 'leave a comment';
    this.cdr.markForCheck();
}

视图

<div formControlName="comment">
   <ng-container #editWysiwigContainer></ng-container>
</div>

任何帮助都是非常欢迎的,这将是与Ivy一起获得的一个很酷的功能

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)