Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda