【发布时间】:2017-08-06 00:31:15
【问题描述】:
我正在尝试在 Ionic 2 应用程序中显示 Youtube 视频,并使用从 JSON 数据馈送中提取的 URL。
在详细页面的构造函数中设置 Youtube url 时可以显示单个视频,但我需要详细页面来显示 JSON 提要中每个视频的视频。
以下是如何在 Ionic 2 中的 detail.ts 和 detail.html 中显示单个 Youtube 视频:
1
import {SafeResourceUrl, DomSanitizer} from '@angular/platform-browser';
2
videoUrl: SafeResourceUrl;
constructor(private domSanitizer: DomSanitizer, public navCtrl: NavController) {
this.videoUrl = this.domSanitizer.bypassSecurityTrustResourceUrl('https://www.youtube.com/embed/DuwXCFyo4-w')
}
3
<iframe width="100%" height="315" [src]="data.youtube" frameborder="0" allowfullscreen></iframe>
ios 调整
<allow-navigation href="https://*youtube.com/*"/>
我需要对 detail.ts 进行一些代码调整以允许 任何 Youtube url?
这是详细信息页面上 Plunker 中显示的 Youtube http://plnkr.co/edit/Ar2whVFCmBAbE7fxA3nf?p=preview
我看到的一个解决方案如下,但似乎无法正常工作:
transform(videoId: string): SafeResourceUrl {
return this.domSanitizer.bypassSecurityTrustResourceUrl(
https://www.youtube.com/embed/${videoId});
}
【问题讨论】:
标签: javascript angular typescript ionic2