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

68
Views
Función de llamada angular para capturar div y esperar la captura antes de continuar

Tengo un método que captura un div. Llamo a este método llamado capture() desde otro método.

Aquí está el código:

 theimage; // define the variable callcapture() { // do stuff this.capture(); // Call the method here // Do other stuff below BUT (Do not run the rest of the code until "this.capture() has finished ") } capture() { const element = document.getElementById("capture") as HTMLCanvasElement; html2canvas(element).then((canvas) => { this.theimage = canvas.toDataURL(); }); }

¿Cómo puedo hacer esto?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

¿Qué tal usar @viewChild de Angular para eso? Rara vez es una buena idea usar métodos JS nativos como getElementById , getElementsByClassName , etc. en una aplicación Angular.

 <canvas #myCanvas></canvas>
 @ViewChild('myCanvas', {static: false}) canvasElem: ElementRef;

Y luego trabajas con eso:

 const context = this.canvasElem.nativeElement.getContext("2d"); const base64:string = this.canvasElem.nativeElement.toDataURL();
about 4 years ago · Juan Pablo Isaza Report

0

Puede devolver la promesa y usar otra then asegurarse de que el elemento ya se haya capturado :

 callcapture() { // do stuff this.capture().then(() => { // Do other stuff below BUT (Do not run the rest of the code until "this.capture() has finished ") }); } capture() { const element = document.getElementById("capture") as HTMLCanvasElement; return html2canvas(element).then((canvas) => { this.theimage = canvas.toDataURL(); }); }
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!