我有這個 *ngFor 回圈。它在每個第二個元素之后呈現一個 h1 標簽。現在我需要在這個標簽中呈現不同的內容
<ng-container *ngFor="let card of cards; index as i">
<mat-card>
<div >
<a target="_blank">
{{card.title}}
</a>
</div>
<div>
<div >
<a target="_blank">
<small>{{card.pages}}</small>
</a>
</div>
</div>
</mat-card>
<h1 *ngIf="(i % 2) == 1">First tag</h1>
</ng-container>
示例圖片
uj5u.com熱心網友回復:
<h1 *ngIf="(i % 2) == 1">{{h2Content}}</h1>
在組件中
interval(1000).subscribe(()=>this.h2Content="SomeNewContentTakenFromSomewhereElse"));
這將允許您以this.h2Content某種方式分配新內容(取決于您如何)
uj5u.com熱心網友回復:
也許您可以將索引除以二?
<h1 *ngIf="(i % 2) == 1"> This is the {{(i 1)/2}}th content </h1>
并使用此值來確定h1內容。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/392336.html
標籤:有角的
