如何绑定到 angular2 中的 data-* 属性? [英] How to bind to data-* attribute in angular2?

查看:23
本文介绍了如何绑定到 angular2 中的 data-* 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有非常大的单元格网格,我想添加数据行和数据列属性值并从模型绑定.如何从 angular2(Dart 中的 beta0)绑定数据行.

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).

与 data-row="{{boundVal}}" 绑定似乎不起作用.(输出html中没有出现数据属性)

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

例如

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

推荐答案

这应该可以满足您的需求

This should do what you want

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

这篇关于如何绑定到 angular2 中的 data-* 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆