我想做的是:
从我的angular(在Typescript中!没有javascript!)应用程序中的html对象中获取图像数据,并将其发送到我的其余服务器。
这应该由我的服务set_Image
来完成。
到目前为止,一切正常,并且我获得了正确的数据,与console.log函数一起显示。
http.post(url,Image64).pipe(tap(Image64 => console.log(Image64)));
还可在其他服务功能中很好地发挥作用。
因为我无法访问function (canvas) {}
中的变量,所以我在函数体中声明了必要的变量
但是现在我得到了错误:
"ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'post' of undefined."
我现在在这个问题上工作了两个星期,我所有的研究都无法解决这个问题。 请帮忙。
代码:
import { HttpClient, HttpHeaders } from '@angular/common/http';
import * as html2canvas from 'html2canvas'
const url1 = 'http://localhost:55320/api/Server/';
.
.
.
set_Image(container:string)
{
html2canvas(document.getElementById(container))
.then(function (canvas)
{
var Image64 = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
console.log("CANVAS: ", Image64);
const url = url1 + '0/set_Image';
var http:HttpClient;
http.post(url,Image64).pipe(tap(Image64 => console.log(Image64)));
});
}
答案 0 :(得分:0)
好像在构造函数中一样,您是否为HttpClient Service创建了实例。
构造函数(私有http:HttpClient)
您可以使用Http相关的公共API。
this.http.post()。