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

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

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 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!