我是Angular 2和Ionic 2的新手
.component.js文件
export class HomePage implements OnInit {
private videoListArr = [];
private title = [];
private objArr;
baseUrl: string = 'https://www.youtube.com/embed/';
private homes = [];
constructor(private sanitizer: DomSanitizer, public navCtrl: NavController, private _homeService: HomeService) { }
ngOnInit() {
this._homeService.getHome()
.subscribe(response =>this.homes.push(JSON.parse(JSON.stringify(response))),
error => alert(error),
() => {
this.objArr = this.homes;
this.objArr[0].items.forEach(element => {
var url = element.snippet.resourceId.videoId;
this.title.push(element.snippet.title);
this.videoListArr.push({
videoUrl: this.sanitizer.bypassSecurityTrustResourceUrl(this.baseUrl + url),
videoTitle: element.snippet.title,
videoDesc: element.snippet.description
});
});
}
)
}
}
您可以使用<iframe>
嵌入应用程序中的YouTube视频。
说您的YouTube URL是:https://www.youtube.com/watch?v=A6KGPBFLHIM
您的嵌入代码将是:
<iframe width="560" height="315" src="http://www.youtube.com/embed/a6KGPBflhiM" frameborder="0" allowfullscreen></iframe>
注意:您必须像我一样替换URL。
另外,请在发布任何问题之前进行基本搜索。:)