angular2 標簽中attribute和property
阿新 • • 發佈:2017-09-16
指令 例如 angular 需要 隨著 100% 異同 order rop
原鏈接:http://blog.csdn.net/erciyuan_nuonuo/article/details/60971696
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;
angular2 標簽中attribute和property