简体   繁体   English

如何在ionic中使用html5 onerror函数

[英]How to use html5 onerror function in ionic

i am building a video app with ionic, I want to play a video, but if the video is not available, I will like to use the onerror fi=unction to change the video source so it will play another video, here is my code我正在使用 ionic 构建视频应用程序,我想播放视频,但是如果视频不可用,我想使用 onerror fi=unction 更改视频源,以便它播放另一个视频,这是我的代码

<video src="test.mp4" (onerror)="this.src='{{service.ApiURL+video.vid_path}}'"></video> 

I got this error in the console我在控制台中收到此错误

    ERROR Error: Uncaught (in promise): Error: Template parse errors:
    Parser Error: Got interpolation ({{}}) where expression was expected at column 10 in [this.src='{{service.ApiURL+video.vid_path}}'] in ng:///HomePage/template.html@28:45 
   <video src="test.mp4" (onerror)="[ERROR ->]this.src='{{service.ApiURL+video.vid_path}}'"

Please what am I doing wrong, how can i solve this issue请问我做错了什么,我该如何解决这个问题

you are better off doing this with a function rather than embedding logic in template.您最好使用函数而不是在模板中嵌入逻辑来执行此操作。

 <video src="test.mp4" (onerror)="setSource(this)"></video> 

In your component:在您的组件中:

 setSource(element) {
  element.src = this.service.apiURL + this.video.vid_path;
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM