html Angular 5嵌入网址

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Angular 5嵌入网址相关的知识,希望对你有一定的参考价值。

import { Component, OnInit } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

@Component({
  selector: 'video-list',
  templateUrl: './video-list.component.html',
  styleUrls: ['./video-list.component.css']
})
export class VideoListComponent implements OnInit {

  title = "Video list title"
  videoList = [
    {
      name: 'Item 1',
      slug: 'item-1',
      embed: '2p89smQck44',
    },
    {
      name: 'Item 2',
      slug: 'item-2',
      embed: '2p89smQck44',
    },
    {
      name: 'Item 3',
      slug: 'item-3',
      embed: '2p89smQck44',
    },
  ]

  constructor(private sanitizer: DomSanitizer) { }

  ngOnInit() {
  }

  getVideoURL(embed) {
    return this.sanitizer.bypassSecurityTrustResourceUrl('https://www.youtube.com/embed/' + embed);
  }

}
<div *ngFor="let video of videoList">
  <a href="videos/{{ video.slug }}">{{ video.name }}</a>
  <iframe width="560" height="315" [src]="getVideoURL(video.embed)" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div>

以上是关于html Angular 5嵌入网址的主要内容,如果未能解决你的问题,请参考以下文章

使用 Angular js 嵌入 Html 页面

Angular 1.5 中的多级嵌入

在 Angular 1.5 中,如何从子组件编译父组件的 html?

创建一个 Angular 组件来显示一组 html 表格单元格以嵌入到其他表格中

Angular:嵌入,设置SVG元素的颜色

如何在Angular 4中使用ngStyle作为背景网址