ngFor youtube与Angular2中的Domsanizer链接

ngFor youtube与Angular2中的Domsanizer链接,angular,youtube,sanitize,angular-dom-sanitizer,Angular,Youtube,Sanitize,Angular Dom Sanitizer,我的模拟内存数据库中有youtube链接,我想从youtube上下载这些视频 let videos: any[] =[ {videoURL: "ZOd5LI4-PcM"}, {videoURL: "d6xQTf8M51A"}, {videoURL :"BIfvIdEJb0U"} ]; 像这样 我使用服务将我的组件连接到服务器,现在在html中,我 让我们看一看视频。在iframe标记内。。是的 &l

我的模拟内存数据库中有youtube链接,我想从youtube上下载这些视频

   let videos: any[] =[
            {videoURL: "ZOd5LI4-PcM"},
            {videoURL: "d6xQTf8M51A"},
            {videoURL :"BIfvIdEJb0U"}

        ];
像这样

我使用服务将我的组件连接到服务器,现在在html中,我 让我们看一看视频。在iframe标记内。。是的

<iframe src=v.videoURL></iframe>

可以创建管道,如:

@Pipe({ name: 'safe' })
export class SafePipe implements PipeTransform {
  constructor(private sanitizer: DomSanitizer) {}
  transform(url) {
    return this.sanitizer.bypassSecurityTrustResourceUrl(url);
  }
}
并按以下方式使用:

<div *ngFor="let video of videos">
  <iframe [src]="('https://www.youtube.com/embed/' + video.videoURL) | safe"></iframe>
</div>

另见

<div *ngFor="let video of videos">
  <iframe [src]="('https://www.youtube.com/embed/' + video.videoURL) | safe"></iframe>
</div>