我是 Angular2 的新手。当 iam 绑定属性时,我曾经按照以下方式进行操作。
示例 1:
<input type="number" [max]="variableName">
Run Code Online (Sandbox Code Playgroud)
示例2:
<select [(ngModel)]="selectedItem">
<option *ngFor="let item of itemList" [value]="item.value" [selected]="selectedItem==item.value">{{item.name}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
有时这些绑定曾经失败。
然后我使用以下语法通过后缀 attr 来绑定属性。为了它。
示例 1:
<input type="number" [attr.max]="variableName">
Run Code Online (Sandbox Code Playgroud)
示例2:
<select [(ngModel)]="selectedItem">
<option *ngFor="let item of itemList" [value]="item.value" [attr.selected]="selectedItem==item.value">{{item.name}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
这些语法有时像魅力一样工作。
请帮助我了解这两种绑定之间的区别,[attributename]以及[attr.attributeName]使用这些特定语法的重要性。