Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何将插值设置为Angular中的样式属性?_Css_Angular - Fatal编程技术网

Css 如何将插值设置为Angular中的样式属性?

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"> <-

在创建这个问题之前,我已经阅读了所有存在的问题,没有一个答案解决了我的问题

我正在从API获取数据,{{album.image[3][text]}-是指向.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>
链接到我的回购->

在图片上,您可以看到相册的网格,其中包含相册名称、艺术家名称和指向相册封面文件的链接,这些文件需要是背景图像 您缺少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>