【问题标题】:unsafe value used in a resource URL context with angular 5角度为 5 的资源 URL 上下文中使用的不安全值
【发布时间】:2018-03-22 18:26:46
【问题描述】:

想要将此 iframe 嵌入到我的模板中,但出现错误 这里是iframe代码,要放在组件的模板里面

<iframe [src]="http://www.youtube.com/embed/{{show.trailer}}"
 width="560" height="315" frameborder="0" allowfullscreen></iframe>

这里是类型脚本文件

import { Component, OnInit } from '@angular/core';
import { Show } from '../show';
import { ActivatedRoute } from '@angular/router';
import { ShowService } from '../show.service';

@Component({
selector: 'app-show-details',
templateUrl: './show-details.component.html',
styleUrls: ['./show-details.component.css']
})
export class ShowDetailsComponent implements OnInit {

show: Show;

constructor( 
private route: ActivatedRoute,
private showService: ShowService
) { }

ngOnInit(): void {
this.getShows();
}

【问题讨论】:

    标签: angular iframe angular5


    【解决方案1】:

    是否定义了 show 变量?

    尝试将您的 iframe 代码更改为此

    <iframe [src]="http://www.youtube.com/embed/{{show?.trailer}}"
     width="560" height="315" frameborder="0" allowfullscreen></iframe>
    

    显示?.预告片

    判断显示变量是 != null 还是 undefined

    【讨论】:

    • 是的,它以数组的形式在 mock.show.ts 文件中定义
    • 试了节目?.trailer ,给出错误“报价不支持评估!”
    • 请帮我看看他们有什么其他方法
    • 你在插值上下文中使用过吗{{show?.trailer}}
    • 实际上我已经通过在 Angular 中创建管道并导入 { DomSantizier } 解决了这个问题,但现在我遇到了浏览器的另一个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多