angular - Firebase图像URL不起作用Angular NgStyle
问题描述
我在通过 firebase 资源图像 URL 渲染图像时遇到了挑战。
模板代码如下:
<div [ngStyle]="{'background-image': 'url(https://firebasestorage.googleapis.com/v0/b/app.appspot.com/o/images%2Fdownload%20(1)-1573413772018?alt=media&token=6dacb361-c996-4cbf-a672-73ab449e149f
dgg)', 'background-position': 'center',
'background-repeat': 'no-repeat',
'background-size': 'cover'}" class="img-wrapper"></div>
当我在开发工具中检查元素时,background-image
没有应用道具
我在这里想念什么?
更新
我已经尝试清理 url 并使用下面的代码
<div [style.background-image]="sanitizer.bypassSecurityTrustStyle(article.articleImgUrl)" [ngStyle]="{'background-position': 'center',
'background-repeat': 'no-repeat',
'background-size': 'cover'}" class="img-wrapper"></div>
<div class="content-wrapper">
解决方案
我通过在模板中调用函数让它工作:
[style.background-image]="article.getImageUrl()";
在类文件中,我有一个函数的实现:
const getImageUrl = () => this.sanitizer.bypassSecurityTrustStyle(`url(${articleData.articleImgUrl})`);
推荐阅读
- javascript - 使用条件与地图
- python - 循环赛中无限制的休息球员
- javascript - 节点 EJS 包的漏洞?
- amazon-web-services - 为什么从 AWS RDS 导出到镶木地板时表格会分段
- python - Django:返回由外键分组的最大值的id
- angular - 在关闭它以在 Angular 中显示网络状态后再次显示小吃栏
- go - 无论如何验证Golang中第一个结构的嵌套结构项的字段?
- sql - 尝试旋转包含 case 语句的表
- javascript - 逐块上传大型视频文件(如 2gb)并添加这些块以使用 javascript ajax 和 django 获取原始文件,无需任何 api 调用
- python - Dash - 如何在不点击按钮的情况下回调自动刷新?