我有一个显示图像的 for 循环。该图像是其容器的背景图像。
图像在 for 循环的每次迭代中都会发生变化。
编码:
<div class="row">
<h4 id="rooms"><strong>Rooms</strong></h4>
<button id="roomlinkbutton" class="linkbutton">+Room</button>
</div>
<div class="row" id="roomsrow"> <!--room row-->
<div *ngFor="let room of venueprofileobject.rooms; let i=index" class="col-md-4"> <!--room item-->
<div class="imagecontainer img-responsive imagefullheight"
[style]=" background-image: url(room.image[0]);">
</div>
<h5 class="roomnameprivacy"><strong>{{room.name}} | {{room.privacy}}</strong></h5>
<button (click)="deleteroom(i)" class="deleteroom btn-danger">Delete</button>
</div> <!--room item-->
保存图像的代码:
rooms:[
{
pk: 1,
name: 'no',
description: 'no',
privacy: 'yeah',
image: ['nifty porno image'],
seatedcapacity: 2,
standingcapacity: 2,
amenities:['k'],
setuptypes:['k'],
filtercompliantroom: false
},
]
但我不确定如何将背景图像 url 值与图像位置绑定。
我试过了
style=" background-image: url({{room.image[0]}});">
失败了
[style]=" background-image: url(room.image[0]);">
这也失败了
[style.background-image]="url(room.image[0])"
也失败了
[ngStyle]="{'background-image': 'url('room.image[0]')'}"
失败的
建议?
目前正在查看此页面以查看是否可以找到答案:https ://www.concretepage.com/angular-2/angular-2-ngstyle-and-style-binding-example