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

94
Visualizações
Accessing Angular Component's DOM children

I'm trying to create an Angular reusable button component. Right now, it is used like so:

<fun-button
  [disabled]="true">
  [label]="'button label'"
>
</fun-button>

The template for fun-button looks like this:

<button>
  {{this.label}}
</button>

So far, so good. Everything works.

Now I would like to modify fun-button so that it is used more like an HTML button:

<fun-button>
  child button label
</fun-button>

How can I access fun-button's DOM children, which in this case is the string 'child button label'?

Is such a thing even possible? I've seen a bunch of answers that involve tagging the child elements, but in my case I want to accept any arbitrary children.

Thanks!

EDIT, WITH ANSWER:

Turned out to be incredibly easy, thanks MikeOne. Just made the template look like this:

<button>
  <ng-content></ng-content>
</button>

And then use like this:

<fun-button>
  child button label
</fun-button>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Made the template look like this:

<button>
  <ng-content></ng-content>
</button>

And then use like this:

<fun-button>
  child button label
</fun-button>
about 4 years ago · Juan Pablo Isaza Relatório
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