5

I found a problem that I do not know how to solve.

If you use this template, so there is no problem:

<li *ngFor="#supplier of supplierList | async">
    <a (click)="changeSupplier($event)">
        <span>{{supplier.id}}: {{supplier.name}}</span>
    </a>
</li>

Output is e.g.:

<li>
    <a>
        <span>1: Sony</span>
    </a>
</li>
<li>
    <a>
        <span>2: Samsung</span>
    </a>
</li>

If I edit a template and try to set the "supplier.id" into html attribute "data-supplierid":

<li *ngFor="#supplier of supplierList | async">
    <a (click)="changeSupplier($event)" data-supplierid="{{supplier.id}}">
        <span>{{supplier.name}}</span>
    </a>
</li>

An error appears:

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>
Mark Rajcok
  • 362,217
  • 114
  • 495
  • 492
JaSHin
  • 211
  • 2
  • 16
  • 43

1 Answers1

12

Default is property binding. For attribute binding use either

attr.data-supplierid="{{supplier.id}}"

or

[attr.data-supplierid]="supplier.id"
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567