Cannot read property 'viewContainerRef' of undefined

前端 未结 8 762
鱼传尺愫
鱼传尺愫 2021-01-01 13:50

I am trying to display a dynamic component similar (not exact) to the example in angular docs.

I have a dynamic directive with viewContainerRef

@Dire         


        
8条回答
  •  北海茫月
    2021-01-01 14:07

    Noted that I face the same problem if directive selector (dynamicComponent in this case) is at :

    1. first element of the component

    2. parent element with *ngIf condition

    Hence, I avoid it by put it inside at non-root tag in the component html & load component to viewContainerRef only when the condition match.

提交回复
热议问题