簡體   English   中英

如何在Angular中獲取Table(array)索引到組件

[英]How to get Table(array)index in to component in Angular

我做了2個dim數組來實現html頁面上的數據,

<tbody>
   <tr *ngFor="let i of myarray2">
     <td  *ngFor="let j of i"> {{j}} 
     </td>
   </tr>
</tbody>

看起來像這樣:

在此處輸入圖片說明

我需要一個函數,例如單擊加號時,我要將數組(i和j)的索引值傳遞到組件(.ts文件)中。

index設置一些其他變量,並在您的(單擊)處理程序中使用它們:

<tbody>
    <tr *ngFor="let subarray of myarray2; let i = index;">
        <td *ngFor="let item of subarray; let j = index;">
          {{item}}
          <span tabindex="0" (click)="someMethod(i, j)">+</button>
        </td>
    </tr>
</tbody>

我設法在注釋的幫助下獲取了參數。這個也可以。非常感謝

html

 <tbody>
                            <tr *ngFor="let i of myarray2 ; let indx1 = index" [attr.data-index]="indx1">
                            <td  *ngFor="let j of i ; let indx2 = index" [attr.data-index]="indx2"  > {{j}} 
                            <button *ngIf="j=='0.0 h'" (click)="getIndexofTable(indx1, indx2)" class="fa fa-plus" > </button>
                             </td>

                        </tr>

打字稿

getIndexofTable(index_value:number,index_value2:number){}

暫無
暫無

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

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