Css 如何将插值设置为Angular中的样式属性?
在创建这个问题之前,我已经阅读了所有存在的问题,没有一个答案解决了我的问题 我正在从API获取数据,{{album.image[3][text]}-是指向.png文件的链接,我想将其设置为。下面是我的代码示例:Css 如何将插值设置为Angular中的样式属性?,css,angular,Css,Angular,在创建这个问题之前,我已经阅读了所有存在的问题,没有一个答案解决了我的问题 我正在从API获取数据,{{album.image[3][text]}-是指向.png文件的链接,我想将其设置为。下面是我的代码示例: <div class="album-grid"> <div *ngFor="let album of albums"> <div class="album"> <-
<div class="album-grid">
<div *ngFor="let album of albums">
<div class="album"> <--! I want here to set a backgroundImage for each album-->
<h4>{{ album.name }},</h4>
<h5>by {{ album.artist.name }}</h5>
<p>{{ album.image["3"]["#text"] }}</p> <--! this is the link to .png file I'm getting from server -->
</div>
</div>
</div>
链接到我的回购->
在图片上,您可以看到相册的网格,其中包含相册名称、艺术家名称和指向相册封面文件的链接,这些文件需要是背景图像
您缺少url部分
在您的存储库中尝试以下操作
<div class="album" [ngStyle]="{ 'backgroundImage': 'url('+ album.image['3']['#text'] + ')'}">
<h4>{{ album.name }},</h4>
</div>
<h5>by {{ album.artist.name }}</h5>
</div>
<div class="album" [ngStyle]="{ 'backgroundImage': 'url('+ album.image['3']['#text'] + ')'}">
<h4>{{ album.name }},</h4>
</div>
<h5>by {{ album.artist.name }}</h5>
</div>