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

282
Vistas
How could I get Dom Element in *ngIf with angular 4

In my page, I have 4 steps using *ngIf to switch between each div, just like

<div *ngIf="step===1"></div>
<div *ngIf="step===2"></div>
<div *ngIf="step===3"></div>
<div *ngIf="step===4"></div>

And I have a canvas element in step 2 to render using data from step 1. My problem was, when user click the next step button, I change step = 2, and I need to render canvas. But as we know, the canvas element won't exist until angular rendered UI.

So is there a way to get the canvas element after angular rendering?

Though I know [hidden] instead of *ngIf could do this, but is there a *ngIf way? setTimeout was not in my concern.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Not 100% sure this works, but worth a try:

 <div *ngIf="...">
   <canvas #canvas>
constructor(private cdRef:ChangeDetectorRef) {}

@ViewChild('cd') canvas:ElementRef;

step = 1;
nextStep() {
  this.step++;
  this.cdRef.detectChanges();
  console.log(this.canvas.nativeElement);
}
over 4 years ago · Santiago Trujillo Denunciar
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