从API加载图像后如何对图像执行任何操作

时间:2019-10-09 06:41:12

标签: angular angular7 angular8

我制作了一个API,该API返回图像的URL。使用Angular 8,我正在渲染该图像。到这里为止一切正常。

我想在渲染该图像后执行 函数。我正在编写该动作,但是它在图像渲染之前 被执行。渲染完图像后,我有什么方法可以执行该功能?

<div id="viewPng" class="uploader">
     <img id="file-image" [src]="imageUrl" alt="Preview" usemap="shapes-map">
     <map name="shapes-map">
          <area shape="rect" title="Square" coords="235, 758, 1126, 942" href="/wp-conF,<nt/uploads/square.png" target="_blank" />
     </map>
</div>
this._pvgfpService.pdfToPng(formData).subscribe(data => {
  this.imageUrl = "https://www.google.com/imgres?imgurl=https%3A%2F%2Fd2eip9sf3oo6c2.cloudfront.net%2Ftags%2Fimages%2F000%2F000%2F300%2Ffull%2Fangular2.png&imgrefurl=https%3A%2F%2Fegghead.io%2Fcourses%2Fget-started-with-angular&docid=f68td0wdokO9hM&tbnid=yBO6E6F_jZlf5M%3A&vet=10ahUKEwioiY7Mx47lAhWj6XMBHWtFC7MQMwhoKAEwAQ..i&w=800&h=800&bih=669&biw=1299&q=Angular%20Image&ved=0ahUKEwioiY7Mx47lAhWj6XMBHWtFC7MQMwhoKAEwAQ&iact=mrc&uact=";
  alert("Hello World");
});

在这里,我得到imageUrl的值,它应该将图像渲染到前端,然后应该执行alert,但是alert在图像渲染之前被执行。

我也尝试过在alert之外编写subscribe,但是alert仍然要先执行。

1 个答案:

答案 0 :(得分:2)

您可以像使用load事件

<img id="file-image" [src]="imageUrl" alt="Preview" (load)="onImageLoad()" usemap="shapes-map">

ts部分

onImageLoad(){
alert("loaded")
}

demo