【问题标题】:How to Use ngFor for multiple components?如何将 ngFor 用于多个组件?
【发布时间】:2021-06-25 15:12:10
【问题描述】:

所以,我正在尝试将 ngFor 用于 10 个不同的组件。

类似的东西:

<ion-slide class="page-slide" *ngFor="let item of slideArr">
 <ion-card class="page-slide-card">
  <ion-card-content> {{item.title}}
    <component of number x></component of number x>
  </ion-card-content>
 </ion-card>
</ion-slide>

有 10 个组件。每个离子载玻片各一个。除了ngIf,还有其他方法可以让它们加载到屏幕上吗?

【问题讨论】:

  • 我会说抽象一个通用组件并使用@Input() 传递特定于每次迭代的数据,而不是使用 10 个不同的组件。

标签: arrays angular typescript ionic-framework


【解决方案1】:

这些是不同的组件吗?在这种情况下,NgSwitch 可能会很有用。

https://angular.io/api/common/NgSwitch

【讨论】:

    猜你喜欢
    • 2017-09-13
    • 2023-03-25
    • 2016-05-26
    • 1970-01-01
    • 2017-07-21
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    相关资源
    最近更新 更多