一般情况下,我们只需要添加[]
工作示例:
<input [type]="myInputType" [(ngModel)]="myValue" />
但有时使用[attr.]
强制要求[attr.]
的示例:
<svg>
<path [attr.fill]="part.color[attr.d]="part.d"
[attr.transform]="part.transform"></path>
</svg>
我无法确定我是否需要(仅通过实际操作来实验),这是令人不安的。规则是什么?
答案 0 :(得分:2)
没有attr.
Angular将绑定到属性。
DOM的DOM或querySelector
中没有属性。
某些属性会被元素本身反映到属性中,这又使其可用于CSS或查询(class
,disabled
,...)。
另见Properties and Attributes in HTML
如果没有具有该名称的属性,则只能绑定到属性。因为Angular需要attr.