在angular应用程序中从html对象获取imagedata并将其发送到rest服务器

在angular应用程序中从html对象获取imagedata并将其发送到rest服务器,angular,html2canvas,Angular,Html2canvas,我想做的是: 从angular(Typescript!无javascript!)应用程序中的html对象获取imagedata并将其发送到rest服务器。 这应该由我的服务通过功能set\u Image完成 到目前为止,一切正常,我得到了正确的数据,如console.log函数所示。 还有http.post(url,Image64).pipe(点击(Image64=>console.log(Image64))在其他服务功能中运行良好 因为我无法访问函数(canvas){}中的变量,所以我在函数体

我想做的是:

从angular(Typescript!无javascript!)应用程序中的html对象获取imagedata并将其发送到rest服务器。 这应该由我的服务通过功能
set\u Image
完成

到目前为止,一切正常,我得到了正确的数据,如console.log函数所示。 还有
http.post(url,Image64).pipe(点击(Image64=>console.log(Image64))在其他服务功能中运行良好

因为我无法访问
函数(canvas){}
中的变量,所以我在函数体中声明了必要的变量 但现在我发现了一个错误:

"ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'post' of undefined."
我现在在这个问题上工作了两周,我所有的研究都无法解决这个问题。 请帮忙

守则:

从'@angular/common/http'导入{HttpClient,HttpHeaders};
从“html2canvas”导入*作为html2canvas
常量url1=http://localhost:55320/api/Server/';
.
.
.
设置图像(容器:字符串)
{      
html2canvas(document.getElementById(容器))
.then(功能(画布)
{
var Image64=canvas.toDataURL(“image/png”).replace(“image/png”、“image/octet-stream”);
log(“CANVAS:”,Image64);
const url=url1+'0/set_Image';
var-http:HttpClient;
http.post(url,Image64).pipe(点击(Image64=>console.log(Image64));
});

}
似乎在构造函数中,您已经为HttpClient服务创建了实例

构造函数(专用http:HttpClient)

您可以使用访问Http相关的公共API


this.http.post()。。。http的类型为“any”。在这个机构中,我没有权限访问我的变量!在set_Image()方法中,set const me=this;Access使用me.http.post()解决了这个问题,将canvas元素存储在区域设置存储中,然后在需要时从那里加载。这是一个错误的做法,但它可以工作,而且我在这个问题上已经有好几天没有时间工作了。时间就是金钱。