[英]How to use property binding with a string in 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: 但是使用这样的
property binding
无法正常工作:
<span *ngFor="let car of Car; let i = index;" >
<img [src]="car/car.id">
</span>
What should I do? 我该怎么办?
您可以使用以下语法进行属性绑定:
[src]="'car/' + car.id"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.