简体   繁体   English

更新动态组件加载器的问题

[英]Issue with updating dynamic component loader

In my ModalComponent, I have the following:在我的 ModalComponent 中,我有以下内容:

_eventEmitterService.modal.subscribe(stream=>{
    var component = ModalTemplateComponent;
    stream.subscribe(msg=>{
        this.componentRef.dispose();
        this.componentRef = null;
    });
    this._dcl.loadIntoLocation(component,_elementRef, 'modal').then((componentRef)=>{
       this.componentRef = componentRef;
    });
})

which worked very well, until I've updated to Angular 17.效果很好,直到我更新到 Angular 17。

In the changelog, I've read that:在变更日志中,我读到:

DynamicComponentLoader.loadIntoLocation has been removed. DynamicComponentLoader.loadIntoLocation 已被删除。 Use @ViewChild('myVar', read: ViewContainerRef) to get hold of a ViewContainerRef at an element with variable myVar.使用@ViewChild('myVar', read: ViewContainerRef) 在变量 myVar 的元素上获取 ViewContainerRef。 Then call DynamicComponentLoader.loadNextToLocation然后调用 DynamicComponentLoader.loadNextToLocation

So, as I understand, I need to add:所以,据我所知,我需要补充:

@ViewChild('selector-modal') child:ModalComponent;

to component that hold the ModalComponent.到包含 ModalComponent 的组件。

However, I am not quite sure how I should then load my new component in the ModalComponent :但是,我不太确定我应该如何在ModalComponent加载我的新组件:

 this._dcl.loadIntoLocation(component,_elementRef, 'modal').then((componentRef)=>{
       this.componentRef = componentRef;
    });

What is the equivalent this in past angular-16 version?过去 angular-16 版本中的 this 是什么?

@ViewChild() should have the read parameter set: @ViewChild()应该有read参数集:

@ViewChild('selector-modal', {read: ViewContainerRef}) child:ModalComponent;

And load nextToLocation should look like:并加载 nextToLocation 应如下所示:

this._dcl.loadNextToLocation(component, this.child).then((cmpRef) => {
  this.cmpRef = cmpRef;
});

See also Angular 2 dynamic tabs with user-click chosen components另请参阅带有用户单击所选组件的 Angular 2 动态选项卡

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM