【发布时间】:2020-07-08 05:13:20
【问题描述】:
当用户单击按钮时,我有一个要求,我需要对该视图进行截图并将其发送回后端,将其保存为 pdf 格式并下载到数据库中。我正在使用 DOM to Image angular 包,它能够截取屏幕截图并将其转换为图像,并且可以保存到客户端系统。
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.
});
}
我确实尝试在 saveAs 之后调用我的服务,但当时我的服务实例不存在
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.
});
});
我需要在里面打电话给我的服务,然后不知道你怎么能帮我解决这个问题?
谢谢,
【问题讨论】: