繁体   English   中英

Angular2 ng用于从索引++添加数字

[英]Angular2 ngFor adding numbers from index ++

我试图增加索引值以创建具有数字1,2,3,4的列表

<tbody>
    <tr *ngFor="let item of queue.truckQueus; let i = index" [attr.data-index]="i">
      <td>{{i ++ }}</td> //this throws an error
      <td>{{item.truck.reg_no}}</td>
    </tr>
</tbody>

如何将1中的数字相加

我也尝试过通过添加

{{i += 1}}

但是总是会得到一个错误表达式。 我要去哪里错了?

<tbody>
    <tr *ngFor="let item of queue.truckQueus; let i = index" [attr.data-index]="i">
      <td>{{i + 1 }}</td>
      <td>{{item.truck.reg_no}}</td>
    </tr>
</tbody>

这必须工作。

如文档中所述。

禁止带有或促进副作用的JavaScript表达式,包括:

  • 分配(=,+ =,-=,...)
  • 用链接表达式; 要么 ,
  • 递增和递减运算符(++和-)

在这里阅读

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM