I am new to Angular2. When iam binding attributes i used to do it in following way.
Example1:
<input type="number" [max]="variableName">
Example2:
<select [(ngModel)]="selectedItem">
<option *ngFor="let item of itemList" [value]="item.value" [selected]="selectedItem==item.value">{{item.name}}</option>
</select>
Some times these bindings used to fail .
Then i used the following syntax to bind attribute by suffixing attr. for it.
Example1:
<input type="number" [attr.max]="variableName">
Example2:
<select [(ngModel)]="selectedItem">
<option *ngFor="let item of itemList" [value]="item.value" [attr.selected]="selectedItem==item.value">{{item.name}}</option>
</select>
These syntax used to work like charm some times.
Please help me in learning the difference between these two bindings [attributename]
and [attr.attributeName]
with there importance in using those particular syntax.