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

199
Views
How to bind data after fetching HTML content in Angular

In Angular 12, I am able to fetch html content from assets folder and display the content using innerHTML. But, the title data is not binded and not displayed in the page.

test-template.html

<h1>{{title}}</h1>
<div>Test Page</div

print-layout.component.html

<div [innerHTML]="myTemplate"></div>

print-layout.component.ts

@Component({
  selector: 'app-print-layout',
  templateUrl: './print-layout.component.html',
  styleUrls: ['./print-layout.component.scss']
})
export class PrintLayoutComponent implements OnInit {

  myTemplate;
  title: string;

  constructor(private sanitizer: DomSanitizer) { }

  ngOnInit() {
      fetch('/assets/templates/test-template.html').then(res => res.text()).then(data => {
        this.myTemplate = this.sanitizer.bypassSecurityTrustHtml(data);
        this.title = 'Hello World'; // assigning value of title which is added in test-template.html
      });    

    setTimeout(() => {
      window.print();
    }, 2000);

  }

}
about 4 years ago · Juan Pablo Isaza
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!