【问题标题】:Ionic ngStyle Background image dynamicallyIonic ngStyle 背景图片动态
【发布时间】:2019-07-31 17:31:27
【问题描述】:

我正在尝试将我的 ngStyle 背景图片绑定到我的卡片上

这是我的代码:

        <ion-slides slidesPerView="1" centeredSlides (ionSlideWillChange)= "slideChange($event)" [ngStyle]= "{'background-image': 'url('+ bg +')'}">

我的 TS 文件

  bg = "images/sample.jpg"

我还使用了 this.bg 和 'background' 而不是 'background-image' 但什么也没发生。谢谢

【问题讨论】:

    标签: css angular typescript ionic-framework ionic3


    【解决方案1】:

    你做得对,这里是working demo

    <ion-slides slidesPerView="1" centeredSlides (ionSlideWillChange)= "slideChange($event)" [ngStyle]= "{'background-image': 'url('+ bg +')'}">
    Test Content for aJaysanity
    </ion-slides>
    

    如果您检查开发者工具,您是否看到您设置的图像出现 404 错误?

    【讨论】:

      猜你喜欢
      • 2020-04-24
      • 2015-10-04
      • 1970-01-01
      • 2015-09-17
      • 2018-10-12
      • 2016-10-01
      • 2015-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多