我有以下显示用户头像的代码:
<div class="dashboard_image" style="background-image:url({{(user.avatar!=null)?user.avatar:'/img/general_user.svg'}})" style="width:200px;height:200px"></div>
如果用户没有任何图像,则user.avatar为空。
在 Chrome 中工作正常,但在 IE 11 中不行。出了什么问题?
最佳答案
尝试使用 ng-style,它就是为此目的而存在的。
https://docs.angularjs.org/api/ng/directive/ngStyle
<div
class="dashboard_image"
style="width:200px;height:200px"
ng-style="{
backgroundImage: 'url(' + (user.avatar!=null ? user.avatar : '/img/general_user.svg') + ')'
}">
</div>
(未测试)
关于AngularJS 和 IE 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38849507/