Angular 角度-阵列中的数据未显示在模板中
有人可以向我解释,为什么我这行没有结果:Angular 角度-阵列中的数据未显示在模板中,angular,Angular,有人可以向我解释,为什么我这行没有结果:{{video?.themes[0].nom} 模板在该行保持为空,没有错误。我可以读取所有其他值。 这里是一个截图: 我的模板: <div class="block5"></div> <div id="videoContainer"> <h3>{{video?.titre }} </h3> <p>{{video?.themes[0].nom}}</p> &l
{{video?.themes[0].nom}
模板在该行保持为空,没有错误。我可以读取所有其他值。
这里是一个截图:
我的模板:
<div class="block5"></div>
<div id="videoContainer">
<h3>{{video?.titre }} </h3>
<p>{{video?.themes[0].nom}}</p>
<h4 class="pl-4">by <a routerLink="/author/{{video?.auteur_id}}" class="authorLink">{{video?.auteur_nom}}</a></h4>
<div class="embedresize">
<div>
<iframe id="iframe"
[src]="url | safe"
frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
</div>
</div>
<p *ngFor="let theme of video?.themes">
<span>{{theme.nom}}</span>
</p>
</div>
export class VideoComponent implements OnInit {
video: Video;
url;
constructor(private apiService: ApiService, private route: ActivatedRoute) {
}
ngOnInit() {
this.route.params.pipe(
switchMap(params => this.apiService.getOneVideoByID(params['id'])),
).subscribe((video: Video) => {
this.video = video;
this.url = "https://www.youtube.com/embed/" + this.getVideoID(this.video.url);
console.log(this.video);
});
}
getVideoID(url: string) {
return this.apiService.getYoutubeVideoID(url);
}
}
控制台中对象的themes
属性是一个字符串数组。请尝试{{video?.themes[0]}
控制台中对象的themes
属性是字符串数组。尝试{video?.themes[0]}
作为您的控制台。屏幕截图中的log(this.video)
输出表明themes
属性为string[]
类型,因此不包括名为nom
的属性
只需这样显示:
{video?.themes[0]}
作为您的控制台。屏幕截图中的log(this.video)
输出表明themes
属性属于string[]
类型,因此不包括名为nom
的属性
只需这样显示:
{{video?.themes[0]}
最合适;)请随意接受答案,以便将此问题标记为已解决。发生在最好的情况下;)请随意接受答案,以便将此问题标记为已解决。