html - 如何在角度 6 中设置背景图像?
问题描述
在这里,我想设置占位符图像,为此我使用 commonurl 路径(this.commonUrlObj.commonUrl)而不是(http://localhost:3000),那么如何使用 angular 6 中的 commonurl 在背景图像中设置图像?
category.component.html
<img [src]="url" style="height: 400px;width: 400px" [ngStyle]="{'background-image': getUrl()}">
类别.component.ts
getUrl(){
return "url('this.commonUrlObj.commonUrl/placeholder.jpg')";
}
普通类.ts
export class CommonClass {
constructor(public commonUrl : string = 'http://localhost:3000'){};
}
解决方案
getUrl(){
return "url('"+this.commonUrlObj.commonUrl+"'/placeholder.jpg')";
}
推荐阅读
- node.js - 为什么`sudo npm uninstall htmlhint -g`没有从`node_modules`中删除`htmlhint`文件夹?不工作?
- python-3.x - 成对的相似代码会产生由“except”语句引起的不同结果
- c++ - 将函数指针传递给模板类
- scala - 我想用一组关键词过滤 Lines read form 文本文件
- c++ - 错误:没有用于调用“CreateFileW”的匹配函数
- java - Eclipse 控制台未显示标准错误
- c# - 实体框架自动增量
- java - 如何从 Firebase 数据库获取密码并与 edittext 匹配?
- angular - Angular - 如何更改文本输入状态
- javascript - 如果数组中包含 JavaScript/lodash 中的特定字符/字符串,如何消除数组中的值?