property:dom元素作为对象附加的内容,例如childNodes、firstChild等 attribute:HTML标签特性是dom节点自带的属性
异同: 1 . 部分属性既属于property,又属于attribute,比如id 2 . attribute初始化后不会再改变;property默认值为初始值,会随着dom更新
所以在angular2中双向绑定实现是由dom的property实现的,所以指令绑定的是property,但是在某些情况下dom不存在某个property比如colspan,rowspan等,这时想要绑定html标签特性需要用到attr
<table width="100%" border="10px solid">
<tr>
<th>Month
</th>
<th>Savings
</th>
</tr>
<tr>
<td [attr.colspan]=colnum>January
</td>
</tr>
<tr>
<td [attr.colspan]=colnum>February
</td>
</tr>
</table>
let colnum:number = 2;
MonthSavingsJanuaryFebruary
转载请注明原文地址: https://ju.6miu.com/read-16316.html