Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use property binding with a string in Angular?

Tags:

angular

Using interpolation to set a property works with this code:

This work for me.
<span *ngFor="let car of Car; let i = index;" >
<img src="car/{{car.id}}">
</span>

but it does not work using property binding like this:

<span *ngFor="let car of Car; let i = index;" >
<img [src]="car/car.id">
</span>

What should I do?

like image 594
蒋建雨 Avatar asked Mar 06 '23 06:03

蒋建雨


1 Answers

You can use the following syntax for property binding:

[src]="'car/' + car.id"
like image 153
ConnorsFan Avatar answered Mar 08 '23 20:03

ConnorsFan