使用Angular在索引中的循环索引

发布于 2025-01-17 23:15:12 字数 678 浏览 2 评论 0原文

我有一个看起来像这样的阵列;

[
 0.{name: name, prod: [0{...}, 1{...}]},
 1.{name: name, prod: [0{...}, 1{...}]},
 2.{name: name, prod: [0{...}, 1{...}]},
 3.{name: name, prod: [0{...}, 1{...}]},
]

因此,现在我使用索引进行ngfor循环:

*ngfor =“让prodlist的p; in i”

index

这显然给了我第一个索引:[0,1,2,3],但是我想为第二个数组索引。

我尝试了:

*ngfor =“让prodlist.prod; index as i”

但似乎不起作用。

我的html:

<ion-col size="6" *ngFor="let p of prodList; index as i">
 <h1>{{p.name}}</h1>
 <p>{{p.prod[i].description}}</p>
 <p>{{p.prod[i].price}}</p>

I have a array that looks like this;

[
 0.{name: name, prod: [0{...}, 1{...}]},
 1.{name: name, prod: [0{...}, 1{...}]},
 2.{name: name, prod: [0{...}, 1{...}]},
 3.{name: name, prod: [0{...}, 1{...}]},
]

So now I do a ngfor loop using the index:

*ngFor="let p of prodList; index as i"

This obviously gives me the first index: [0,1,2,3], however I would like to index the second array.

I have tried:

*ngFor="let p of prodList.prod; index as i"

But does not seem to be working.

my html:

<ion-col size="6" *ngFor="let p of prodList; index as i">
 <h1>{{p.name}}</h1>
 <p>{{p.prod[i].description}}</p>
 <p>{{p.prod[i].price}}</p>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文