参见英文答案 >
Angular 2 data attributes2个
我发现了一个我不知道如何解决的问题.
我发现了一个我不知道如何解决的问题.
如果您使用此模板,那么没有问题:
<li *ngFor="#supplier of supplierList | async"> <a (click)="changeSupplier($event)"> <span>{{supplier.id}}: {{supplier.name}}</span> </a> </li>
输出是例如:
<li> <a> <span>1: Sony</span> </a> </li> <li> <a> <span>2: Samsung</span> </a> </li>
如果我编辑模板并尝试将“supplier.id”设置为html属性“data-supplierid”:
<li *ngFor="#supplier of supplierList | async"> <a (click)="changeSupplier($event)" data-supplierid="{{supplier.id}}"> <span>{{supplier.name}}</span> </a> </li>
出现错误:
Can't bind to 'supplierid' since it isn't a known native property ("i> <li *ngFor="#supplier of supplierList | async"> <a (click)="changeSupplier($event)" [ERROR ->]data-supplierid="{{supplier.id}}"> <span>{{supplier.name}}</span> </a>