How to bind to data-* attribute in angular2? [duplicate]

不羁岁月 提交于 2019-11-26 07:30:04

问题


Assuming I have really large grid of cells I want to add data-row and data-col atribute values and bind from model. How can I bind data-row from angular2 (beta0 in Dart).

Binding with data-row=\"{{boundVal}}\" does not seem to work. (no data attribute appears in output html)

eg.

<table>
  <tr *ngFor=\"#row of rows\" >
      <td *ngFor=\"#cell of row.cells\" data-row=\"{{row.index}}\" data-col=\"{{cell.index}}\" >
      </td>
  </tr>
</table>

回答1:


This should do what you want

[attr.data-row]="row.index" [attr.data-col]="cell.index"


来源:https://stackoverflow.com/questions/34412103/how-to-bind-to-data-attribute-in-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!