question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple dynamic content projection

See original GitHub issue

Need 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
alxhubcommented, May 7, 2019

@DenisRoss: As others have mentioned, a pretty standard way to do this is to use a template directive, and query for TemplateRefs 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.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 15, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found