angular - 通过单击按钮显示图像
问题描述
单击按钮后,我试图在新窗口上显示图像。
但是,有些时候,这是无法做到的。
组件.ts
displayMyImage()
{
this.http.get(this.imagePath, {observe: 'response', responseType: 'blob'}).pipe(map(res =>
{
return new Blob([res.body], {type: res.headers.get('Content-Type')});
})).subscribe(hi =>
{
const xx = URL.createObjectURL(hi);
window.open(xx);
});
}
组件.html
<span (click)='displayMyImage()'>Display</span>
或者
<button (click)="displayMyImage()">Display</button>
我得到了那个例外
你能告诉我我错过了什么吗?非常感谢。
解决方案
您可以声明如下函数以获取图像预览。我想你那里有 imagePath 。
displayMyImage() {
var imagePath = "https://www.howtogeek.com/wp-content/uploads/2018/06/shutterstock_1006988770.png";
window.open(
imagePath,
"Image",
"width=largeImage.stylewidth,height=largeImage.style.height,resizable=1"
);
}
希望这可以帮助。
推荐阅读
- php - 如何在 laravel 中使用嵌套的 foreach 循环来填充子菜单?
- python - 如何计算多个数据帧的行和列?
- ssh - GCP Compute Engine // 连接被拒绝错误:(gcloud.compute.ssh)[/usr/bin/ssh] exited with return code [255]
- r - 没有测试的单元测试
- java - 阵列旋转问题 - 无法获得所需的输出
- spark-streaming - 使用 HAIL 解析 .bgen 文件,而不在单个节点上加载数据
- python - django-heroku 没有安装
- chart.js - 如何更改 Charts.js 中水平条的起点
- java - 无法使用具有文本逗号 csv 的值拆分字符串
- excel - Excel 文件缺少对 Microsoft Windows Common Controls-2 的引用