Skip to content

How to use a templateRef with ndcDynamicContent. #507

Answered by gund
kotarCreative asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think you can render ng-templates directly as they are not renderable by default.
So you need to pre-render TemplateRef into some html node and then grab the ref to that node and pass it in as content:

<ng-template #childTpl>
   ... my ng-content here...
</ng-template>
<div #childContent>
  <ng-container *ngTemplateOutlet="childTpl"></ng-container>
</div>
<ndc-dynamic [ndcDynamicComponent]="dynamicComponent" [ndcDynamicContent]="[[childContent.nativeElement]]"></ndc-dynamic>

But I would recommend to just pass a TemplateRef as an input to a dynamic component and then render it inside of your component.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kotarCreative
Comment options

Answer selected by kotarCreative
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants