【发布时间】:2020-03-16 18:13:18
【问题描述】:
单击按钮后,我正在尝试在新窗口上显示图像。
但是,有些时候,这是无法做到的。
Component.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);
});
}
Component.html
<span (click)='displayMyImage()'>Display</span>
或
<button (click)="displayMyImage()">Display</button>
我收到了that exception
你能告诉我我错过了什么吗?非常感谢。
【问题讨论】:
-
这能回答你的问题吗? Open image in new window
-
您好@ChintanJoshi 先生,非常感谢您的重播。我尝试了您提出的线程的正确答案,但知道 largeImage 的值是
../assets/upload/Ordinaryespdsi2019o4f8dh1584349128317.jpg,这对我不起作用。请问您有解决这个问题的任何想法吗?非常感谢。 -
你的情况下 imagePath 是什么?
-
如果我使用 staticPath 作为
<img id="staticPath" src="../assets/upload/Ordinaryespdsi2019o4f8dh1584349128317.jpg" style="max-width:100px">--> 效果也很好。但是如果我使用 dynamicPath 像<input id='dynamicPath' type="text" value="{{saria2020()}}">--> 那不起作用,知道 saria2020 的值是../assets/upload/Ordinaryespdsi2019o4f8dh1584349128317.jpg在 component.ts 上就像saria2020() : String{return this.specialUser.displayPathImage;}
标签: angular spring-boot