想要在我的模板中嵌入此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();
}
答案 0 :(得分:0)
是否定义了show变量?
尝试将您的iframe代码更改为此
<iframe [src]="http://www.youtube.com/embed/{{show?.trailer}}"
width="560" height="315" frameborder="0" allowfullscreen></iframe>
显示?.trailer
评估show变量!= null或undefined