繁体   English   中英

Angular中的ngStyle背景图像

[英]ngStyle backgroud image in Angular

我使用ngStyle标签到我的div元素来设置图像,但图像不起作用,

我试图设置ngStyle背景如下

<div  [ngStyle]="{'background-image': 'url(${profilePicPrefix + profileService.userDetails.profile_img})'}"  class="profilepic">
</div> 

[ngStyle]="{'background-image': 'url('+ profilePicPrefix + profileService.userDetails.profile_img +')'}"  
// not working - String concatenation 

[ngStyle]="{'background-image': 'url(${profilePicPrefix + profileService.userDetails.profile_img})'}"
// not working

我得到空白屏幕,图像不渲染,但构建成功。

我用过给定的东西,请试一试

 [ngStyle]="{'background-image':'url(' + profileService.userDetails.profile_img + ')'}"

您忘记在括号内添加引号。

试试这个

[ngStyle]="{'background-image': 'url("'+ profilePicPrefix + profileService.userDetails.profile_img +'")'}" 

尝试这个

 [style.background-image]="'url('+ profileService.userDetails.profile_img +')'">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM