【发布时间】:2017-08-16 12:42:47
【问题描述】:
我是 Angular2 的新手。当 iam 绑定属性时,我以前是按以下方式进行的。
示例 1:
<input type="number" [max]="variableName">
示例2:
<select [(ngModel)]="selectedItem">
<option *ngFor="let item of itemList" [value]="item.value" [selected]="selectedItem==item.value">{{item.name}}</option>
</select>
这些绑定有时会失败。
然后我使用以下语法通过后缀 attr 来绑定属性。为它。
示例 1:
<input type="number" [attr.max]="variableName">
示例 2:
<select [(ngModel)]="selectedItem">
<option *ngFor="let item of itemList" [value]="item.value" [attr.selected]="selectedItem==item.value">{{item.name}}</option>
</select>
这些语法曾经有时像魅力一样工作。
请帮助我了解这两个绑定 [attributename] 和 [attr.attributeName] 之间的区别,以及使用这些特定语法的重要性。
【问题讨论】:
标签: javascript angular