How to bind to data-* attribute in angular2?

AngularAngular Dart

Angular Problem Overview


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>

Angular Solutions


Solution 1 - Angular

This should do what you want

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontomaszkubackiView Question on Stackoverflow
Solution 1 - AngularGünter ZöchbauerView Answer on Stackoverflow