Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
Multi slot content projection in angular doesn't work with component

I'm trying to create a component that takes some divs and places them in a specific order depending on the classes defined in the content to project. For this, I've created a component with some ng-content elements with class selectors. It does works if I pass some static HTML, however, if I pass a component it doesn't show anything (except if I use a single slot). I've created an example in StackBlitz that can be found here.

I've defined three different scenarios using the same component:

  1. Passing static HTML and configuring the component to use multiple slots, everything works fine.
    <app-content-formatter>
      <div class="body">This is just a nonsense text</div>
      <div class="head">This is the head.... I guess</div>
    </app-content-formatter>
    
  2. Passing another component and configuring it to use multiple slots, nothing gets rendered
    <app-content-formatter>
      <app-some-text></app-some-text>
    </app-content-formatter>
    
  3. Passing another component and configuring it to use a single slot, everything works (however, the elements are not displayed as it's required)
    <app-content-formatter [multiSlot]="false">
      <app-some-text></app-some-text>
    </app-content-formatter>
    

I'm not sure why this is happening, and there's a huge chance I may have forgotten something (I've started working with angular a few months ago). The sample provided in StackBlitz it's an abstraction of a more complex scenario that requires replacing a component that is used in a big application, the idea is to avoid a lot of changes by reusing the existing classes and structure, that's the reason I'd like to use the content projection.

If I have to guess, I'd say the problem is the selectors, they might change since they're inside a tag with the name of the component itself, which could be a problem as well, as we need to display different controls which will be loaded dynamically (that part was not included in the example since the problem is the content projection).

Thank you everyone in advance for all your help!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda