繁体   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