【问题标题】:How to get Table(array)index in to component in Angular如何在Angular中的组件中获取表(数组)索引
【发布时间】:2018-12-12 23:16:37
【问题描述】:

我做了2个dim-array来在html页面上实现我的数据,

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

看起来像这样:

我需要一个函数,比如当我单击加号时,我想将数组(i 和 j)的索引值传递到我的组件(.ts 文件)中。

【问题讨论】:

  • 您能向我们展示您迄今为止为编写这些函数所做的尝试吗?
  • 我发布了另一个答案

标签: html node.js angular typescript


【解决方案1】:

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>

【讨论】:

    【解决方案2】:

    在评论的帮助下,我设法获得了参数。这个也可以。非常感谢

    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){ }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-29
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 2017-02-01
      • 2015-08-25
      相关资源
      最近更新 更多