簡體   English   中英

ngFor循環中的角度生成組件

[英]Angular generate components in ngFor loop

我有多個組件(超過10個),它們彼此之間略有不同,每個組件向API提出自己的請求。 我想知道如何通過*ngFor生成這些組件,因為現在看起來

<component1 *ngIf="activeTab === 0"></component1>
<component2 *ngIf="activeTab === 1"></component2>
<component3 *ngIf="activeTab === 2"></component3>

並且這個數字有望增長。 有什么辦法可以使我做出類似

list = [
  {
    title: 'Component 1',
    component: Component1
  }
]

<ng-container *ngFor="let item of list">{{item.component}}</ng-container>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM