angular - 如何在动态插入图像源的角度 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");
}
需要一些文章参考或调试帮助。
谢谢!
解决方案
<img (load)='imageLoaded()' class='doc-img' [src]='imageUrl'>
推荐阅读
- javascript - 手机上的摄像头控制不适用于 babylonjs vr
- reactjs - 发生验证错误时处理formik表单
- mysql - 无法使用 ODBC 将用户定义的变量从 MySQL 设置为 Excel
- r - 当它被指定为“列表”类型参数时,我为什么能够将数据框传递给“geom_qq”函数中的“dparams”参数?
- java - REST ASSURED (JAVA):使用 jsonpath 提取值表单响应并使用 excel 输入值进行验证
- php - WP ACF 自动从多个字段创建简码
- intellij-idea - 构建 WAR 文件时出现 java.nio.file.InvalidPathException
- flutter - 我无法在后台获取任何数据
- apollo - 预防:查询进行时存储重置(未在链接链中完成)
- apache-spark - 尝试初始化 SparkContext 时,Amazon EMR 上的标签资源请求无效