如何防止嵌入的YouTube视频反复刷新?
我尝试了很多方法,但几乎所有的方法都得到1个错误,不断重复和刷新视频
getVideoUrl(FileUrls) {
if (this.loadApiDone == true) {
var video = "";
var videos = JSON.parse(FileUrls);
console.log("videos", videos);
if (videos && videos.length !== 0) {
video = videos[0];
let videoUrl = 'https://www.youtube.com/embed/' + video;
console.log("videoUrl", videoUrl);
return this.sanitizer.bypassSecurityTrustResourceUrl(videoUrl);
}
return this.appService.apiRoot + video;
}
}
<a class="img-figure">
<ng-container *ngIf="item.FileUrls">
<iframe *ngIf="item.Type == 0" class="video-container" controls
[src]="getVideoUrl(item.FileUrls)" type="video/mp4">
</iframe>
<img *ngIf="item.Type == 1" class="img-figure" [src]="getImage(item.FileUrls)"
alt="post-image-first" />
</ng-container>
<img *ngIf="item.FileUrls == this.LINK_DEFAULT_IMAGE || item.FileUrls == null || item.FileUrls == undefined"
class="img-figure-first" src="../../assets/images/default.png" alt="post-image" />
</a>
1条答案
按热度按时间r3i60tvu1#
每次angular刷新视图时,
[src]="getVideoUrl(item.FileUrls)"
将再次计算。那你能怎么办
一种可能性是使用新字段
videoUrl
修改item
,以便在定义item.
时计算ts
文件中的getVideoUrl
。所以在你身上