首页 > 解决方案 > Typescript - Check if image src has been fetched and call a function

问题描述

I have the following element on my page:

<img src="https://i.pinimg.com/736x/2c/9d/07/2c9d0704ae49dfde914e2b477bf9279c--stick-figure-profile-pictures.jpg" />

How can I check when the src has been successfully fetched and call a function after that?

标签: angularimagefunctiontypescriptfetch

解决方案


这是一个答案,让我们尝试一次,

html文件,

<img [src]="imagesource" (load)="doSomething()">
<!--(or)-->
<img src="https://i.pinimg.com/736x/2c/9d/07/2c9d0704ae49dfde914e2b477bf9279c--stick-figure-profile-pictures.jpg" (load)="doSomething()">

打字稿文件,

imagesource="https://i.pinimg.com/736x/2c/9d/07/2c9d0704ae49dfde914e2b477bf9279c--stick-figure-profile-pictures.jpg";

doSomething(){
   console.log("Loaded");
   //do your stuff
}

如需更多参考,请访问此处

检测图像何时加载到 img 标签中


推荐阅读