在创建此问题之前,我已阅读了所有存在的问题,但没有一个答案可以解决我的问题。
好吧,我要从API提取数据,{{ album.image["3"]["#text"] }}
-是指向.png文件的链接,我想将其设置为.png的背景图像。这是我的代码示例:
<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>
这是我尝试过的解决方案,但没有一个对我有帮助:
[style.backgroundImage]="album.image['3']['#text']"
[style]="backgroundImage: {{album.image['3']['#text']}"
[ngStyle]="{ 'backgroundImage': album.image['3']['#text'] }"
链接到我的仓库-> https://github.com/paslavskyi9roman/Spotilar
在图片上,您可以看到专辑的网格,其中包含专辑名称,艺术家名称以及指向专辑封面文件的链接,这些文件必须是背景图片,请点击此处
您缺少该url()
部分。
尝试以下操作(如您的存储库中所示)
<div class="album" [ngStyle]="{ 'backgroundImage': 'url('+ album.image['3']['#text'] + ')'}">
<h4>{{ album.name }},</h4>
</div>
<h5>by {{ album.artist.name }}</h5>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句