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

166
Visualizações
Add Component or Directive to HTML template received from the server

Let's say an endpoint returns this HTML:

<div data-type="section">
    <div data-type="section-header">
        Section 1
    </div>
    <div data-type="section-body">
        Lorem ipsum
    </div>
</div>

Above template will be stored in component property sections. In an Angular app we will append this HTML to the page via <div class="sections-container" [innerHtml]="sections"></div>.

Before appending HTML template to innerHtml, is it possible to add component or directive to the HTML template received from the backend?

For example we have HighlightDirective, which will set background to yellow and we want to apply it to data-type="section-header" element, so that HTML template will look like this:

<div data-type="section">
    <div data-type="section-header" appHighlight>
        Section 1
    </div>
    <div data-type="section-body">
        Lorem ipsum
    </div>
</div>

Will Angular automatically recognize the appHighlight directive and add it to the component tree? Or it's necessary to hydrate this HTML template?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The solution that I have found it is wrapped HTML into anonymous component and handle string from BE. Then compile that and looks like everything is ok.

Stackblitz example

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