Multiple dynamic content projection
See original GitHub issueNeed advice about best way how to make multiple dynamic content projection. Situation, than we have parrent component template like this:
<tabs [count] = 'n'>
<div tab_1>...</div>
<div tab_2>...</div>
...
<div tab_n-1>...</div>
<div tab_n>...</div>
</tabs>
And expected that child (Tabs) component template will be like that:
...
<ng-content select='[tab_1]'></ng-content>
<hr/>
<ng-content select='[tab_2]'></ng-content>
...
<ng-content select='[tab_n-1]'></ng-content>
<hr/>
<ng-content select='[tab_n]'></ng-content>
...
In this case we have a problem, because we can’t use ng-content like this one:
<div *ngFor="let item of [1, 2, ... , n - 1, n]]">
<ng-content select='[tab_{{n-1}}]'></ng-content>
</div>
ng-content select is static, we can’t use expression here.
How we can get array of content childs to use it in *ngFor?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Angular 7 Dynamic Content Projection - Stack Overflow
What you want to acomplish is to use content projection in a loop. ... As you can see by usage code, you can...
Read more >Content projection - Angular
This pattern is referred to as multi-slot content projection. With this pattern, you must specify where you want the projected content to appear....
Read more >Angular Content Projection | Use multiple ng-content - YouTube
We will try to pass the dynamic content inside ng- content section. We will also see how the multiple ng- content can be...
Read more >Angular Content Projection using <ng-content> - Anjali Tanpure
Let's understand how we can use <ng-content> to reuse the component and project the contents dynamically. Let's take a simple example. Suppose we...
Read more >Angular Dynamic Content - Antomor
In many cases we would change the content of a component dynamically, ... Content projection; Dynamic templates; Dynamic component creation.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@DenisRoss: As others have mentioned, a pretty standard way to do this is to use a template directive, and query for
TemplateRef
s directly. Here’s an example for you.I’m going to close this issue as there is no bug or feature request here for Angular, but please let me know if that example clarifies things for you.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.