这里我想设置占位符图像,为此我使用 commonurl 路径 (this.commonUrlObj.commonUrl) 而不是 (http://localhost:3000) 那么如何使用 Angular 6 中的 commonurl 在背景图像中设置图像?
类别.组件.html
<img [src]="url" style="height: 400px;width: 400px" [ngStyle]="{'background-image': getUrl()}">
类别.组件.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')";
}
关于html - 如何在 Angular 6 中设置背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52944187/