Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!