首页 > 解决方案 > Ionic ngStyle Background image dynamically

问题描述

I am Trying to bind my ngStyle Background image on my card

Here's my code:

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

my TS file

  bg = "images/sample.jpg"

I used also this.bg and 'background' instead of 'background-image' but nothing happened. Thank you

标签: cssangulartypescriptionic-frameworkionic3

解决方案


你做得对,这是一个工作演示

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

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


推荐阅读