I am trying to display a Youtube video in an Ionic 2 app with URLs nested from a JSON data feed.
Individual videos may be displayed when the Youtube URL is set in the designer on the details page, but I need a detailed page to display the video for each of the videos in the JSON channel.
Here's how an individual Youtube video can be displayed in Ionic 2 in detail.ts and detail.html:
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 tweak
<allow-navigation href="https://*youtube.com/*"/>
What I need is some code tweak in detail.ts to resolve any Youtube url?
Here is Youtube being displayed in Plunker on the details page http://plnkr.co/edit/Ar2whVFCmBAbE7fxA3nf?p=preview

One solution that I saw below, but doesn't seem to work, is:
transform(videoId: string): SafeResourceUrl { return this.domSanitizer.bypassSecurityTrustResourceUrl( https:
source share