【问题标题】:How to perform any action on image, after it loads from API从 API 加载后如何对图像执行任何操作
【发布时间】:2019-10-09 06:41:12
【问题描述】:

我制作了一个返回图像 URL 的 API。使用 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在图像渲染之前被执行。

我也试过在subscribe之外写alert,但alert还是先被执行。

【问题讨论】:

    标签: angular angular7 angular8


    【解决方案1】:

    您可以使用load 之类的事件

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

    ts部分

    onImageLoad(){
    alert("loaded")
    }
    

    demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多