angular - 从 Angular 应用程序中的 html 对象获取图像数据并将其发送到休息服务器
问题描述
我想做的是:
从我的 Angular(在 Typescript!没有 javascript!)应用程序中的 html 对象中获取图像数据并将其发送到我的休息服务器。这应该由我的 service with function 完成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)));
});
}
解决方案
好像在构造函数中,您是否为 HttpClient 服务创建了实例。
构造函数(私有http:HttpClient)
您可以使用 Http 相关的公共 API 访问。
这个.http.post()。
推荐阅读
- node.js - Koa - 在传入请求上设置超时
- c - 可以在模块初始化完成之前删除 linux 内核模块吗?
- ios - 串行队列比同步块更快吗?
- spring-boot - 带有 Spring Boot KeycloakSecurityContext 的 Keycloak 始终为空
- python - Pyinstaller - 转换为 .exe 的 python 脚本未按预期方式执行程序
- r - 在 gg 图中标记下一个点
- android - 使用 RNFetchBlob 从存储中删除文件
- php - Laravel:两个模型路由绑定没有关系
- angular - DOM 异常:标头名称无效
- laravel - Laravel:在 created_at 和 updated_at 之间切换