【问题标题】:how to concatenate a dynamic image path in background image url ionic如何在背景图像url离子中连接动态图像路径
【发布时间】:2019-07-12 15:21:21
【问题描述】:

我正在尝试将静态路径和作为图像路径的动态路径连接到图像 URL 中,每当我在尝试过的路径之间添加 + 时,都会出现语法错误

<div *ngFor="let cat of Cat" class="cus-col" style="background-image: url( 'Static Image Url'  '+ Dynamic Image Url'  ) ">}
        <div class="cus-text">
          <h4>{{cat.name}}</h4>
        </div>
      </div>

【问题讨论】:

    标签: html ionic-framework ionic2 ionic3


    【解决方案1】:

    由于您使用的是 Ionic,因此您应该使用 Angular NgStyle 指令来设置元素样式。

    本例使用动态 url 设置 div 的背景图片:

    <div [ngStyle]="{'background-image': 'url(' + dynamicVariable + ')'}"></<div>
    

    这个例子用一个静态和动态的url来设置一个div的背景图片:

    <div [ngStyle]="{'background-image': 'url(https://www.example.com/images/' + dynamicVariable + ')'}"></<div>
    


    你可以在这里了解更多信息:

    https://codecraft.tv/courses/angular/built-in-directives/ngstyle-and-ngclass/

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 2020-01-01
      • 2020-10-07
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2018-07-10
      • 2013-12-01
      • 2022-10-01
      相关资源
      最近更新 更多