首页 > 解决方案 > 如何在动态插入图像源的角度 2 中使用 onload 事件

问题描述

我想在下载图像时设置某些标志。我尝试在图像标签和调用函数上使用 onload 事件。通过我在下面实现的内容,我收到了错误:

未捕获的 ReferenceError: imageLoaded 未在 HTMLImageElement.onload 中定义

组件.html:

 <img onload='imageLoaded()' class='doc-img' [src]='imageUrl'>

组件.ts:

ngOnInit()
{
  this.getDocumentImage()
}

getDocumentImage()
{
     this.imageUrl= 
this.domSanitizerService.bypassSecurityTrustResourceUrl(`${API.document}/{documentId}`);
}

imageLoaded(){
    alert("image loaded");
}

需要一些文章参考或调试帮助。

谢谢!

标签: angularonload

解决方案


<img (load)='imageLoaded()' class='doc-img' [src]='imageUrl'>

推荐阅读