css - 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
解决方案
你做得对,这是一个工作演示
<ion-slides slidesPerView="1" centeredSlides (ionSlideWillChange)= "slideChange($event)" [ngStyle]= "{'background-image': 'url('+ bg +')'}">
Test Content for aJaysanity
</ion-slides>
如果您检查开发人员工具,您是否看到您设置的图像出现 404 错误?
推荐阅读
- ms-access - DoCmd.Close acForm,“名称”,acSavePrompt 不起作用
- excel - 无法创建 ComObject“Excel.Application”
- javascript - 如何开始使用 React 进行函数式编程?
- java - 如何在 avro 模式中创建包含字符串数组的对象?
- tensorflow - 在密集层之前连接一个输入。[带有 TF 后端的 Keras]
- mysql - 提高 SQL 查询性能
- javascript - 如何测试 Yup.array 中值的唯一性?
- mongodb - 同时查询多个属性,得到一个整体平均值和一个数组
- c# - 是否可以在没有主键的表上将 Entity Framework Core 与现有数据库一起使用?
- sql-server - SQL Server 错误:从字符串转换日期和/或时间时转换失败