0

I have a requirement when the user clicks on the button I need to take a screenshot of that view and send back to the backend save it as pdf in DB and download the same. I am using DOM to Image angular package, Its able to take a screenshot and convert it to image and can be saved as to client system.

public takeScreenShot(){

   domtoimage.toBlob(document.getElementById('my-node'))
      .then(function (blob) {
         window.saveAs(blob, 'my-node.png');
        //I need to make a call to my service to send this blob object to backend.
   });
}

I did try to call my service after saveAs but my service instance doesn't exist inside then

public takeScreenShot(){
    let serviceObj= this.service;    
    domtoimage.toBlob(document.getElementById('my-node'))
        .then(function (blob) {
        window.saveAs(blob, 'my-node.png');
        this.service.sendImage(blob).subscribe(res=>{//save as pdf to client system but this.service doesn't exist inside then.
        //I did try to return blob and assign it, it doesn't work.
       });  
  });

I need to call my service inside then not sure how can you please help me in this?

Thanks,

1 Answer 1

2

you must use arrow function syntax to be able to access this

public takeScreenShot(){
    let serviceObj= this.service;    
    domtoimage.toBlob(document.getElementById('my-node'))
        .then((blob) => {
            window.saveAs(blob, 'my-node.png');
            this.service.sendImage(blob).subscribe(res=>{//save as pdf to client system but this.service doesn't exist inside then.
            //I did try to return blob and assign it, it doesn't work.
       });  
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.