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

221
Visualizações
How to take different templates as an input based on condition using ngTemplateOutlet in angular

I have running Angular 12 application and I want to achieve a scenario where I want to display different html templates without creating components inside parent component using ngTemplateOutlet. All the different templates is a separate html files

parent.component.html

<ng-container [ngTemplateOutlet]="templatePath"> 

<ng-template #test1></ng-template> // displays the content of test1.html
<ng-template #test2></ng-template> //  displays the content of test2.html

templatePath is basically path of the html template which will come as an input property.

parent.component.ts

templatePath = './test1.html'; // not sure how to fetch the html template, so added this

test1.html

<h1>Hello</h1>

This is just a html template file. I don't want to use component for this

test2.html

<h1>Welcome</h1>

This is just a html template file. I don't want to use component for this

I am not sure whether ngTemplateOutlet is the right way to achieve the above scenario. Please suggest what can be used in Angular to achieve this scenario.

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

0

Try this and use your own myVar variable:

<ng-container *ngIf=“myVar === 1; then test1 else test2”></ng-container>
<ng-template #test1></ng-template> // displays the content of test1.html
<ng-template #test2></ng-template> //  displays the content of test2.html
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