* ng对于子阵列对象 - Angular + Firebase

问题描述 投票:1回答:1

我试图使用一个简单的ngFor,但我正在处理一个问题。

宾语

export class Post {
  $key: string;
  title: string;
  subtitle: string;
  postedBy: string;
  imageUrl: string;
  paragraphs: [] = [];
}

我的意图是使用以下HTML代码:

<p *ngFor="let p of databaseService.selectedPost[0].paragraphs">a</p>

意思是我想在我的对象的每个段落中显示一个段落,但是我得到了这个错误:

错误错误:无法找到'object'类型的不同支持对象'[object Object]'。 NgFor仅支持绑定到诸如Arrays之类的Iterables。

我试图在我的第一段使用console.log(this.selectedPost[0].paragraphs.p1);作为p1它实际上有效,但我无法从HTML(它有p1,p2,p3 ......作为名称)这样做。下图为console.log

enter image description here

这是数据库中的对象:

enter image description here

我怎么能这样做?

json angular ngfor
1个回答
1
投票

根据事物的声音,databaseService.selectedPost[0].paragraph是一个对象,正如你所说,你可以直接访问p1

我试过使用console.log(this.selectedPost [0] .paragraphs.p1);作为p1我的第一个段落,它确实有效

如果是这种情况,你可以使用Angular qazxsw poi迭代qazxsw poi

一个工作示例如下:

KeyValuePipe
© www.soinside.com 2019 - 2024. All rights reserved.