亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Angular 在數組中定義的特定索引上運行 *ngFor

Angular 在數組中定義的特定索引上運行 *ngFor

溫溫醬 2023-09-28 15:44:51
我正在使用 *ngFor 循環,但我只希望循環在數組中定義的特定索引上運行(即indexArray = [454,640])。如果我嘗試這樣做,并且 indexArray 有兩個或更多元素,則它不起作用。但如果數組只有一個元素(即indexArray=[565]),它就可以工作。<div *ngFor="let item of items; index as i">   <table *ngIf="i == indexArray">
查看完整描述

3 回答

?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

您可以使用.indexOf(i)并檢查它是否在您的indexArray變量中。


<div *ngFor="let item of items; index as i">

  <table *ngIf="indexArray.indexOf(i)> -1"> 

  <!-- REST OF THE CODE -->


查看完整回答
反對 回復 2023-09-28
?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

您可以執行以下操作:


<div *ngFor="let item of items; index as i">

  <table *ngIf="indexArray.includes(i)">

    enter code here...

  </table>

</div>

這是一個工作示例


查看完整回答
反對 回復 2023-09-28
?
波斯汪

TA貢獻1811條經驗 獲得超4個贊

像這樣創建索引數組


public indexArray: array = [454,640];

像下面那樣做。


<div *ngFor="let item of items; index as i">

  <table *ngIf="indexArray.indexOf(i)> -1">

    enter code here...

  </table>

</div>

如果您有任何疑問,請告訴我。


查看完整回答
反對 回復 2023-09-28
  • 3 回答
  • 0 關注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號