简体   繁体   English

AngularJS和IE问题

[英]AngularJS and IE issue

I have the following code that shows the user avatar: 我有以下代码显示用户头像:

<div class="dashboard_image" style="background-image:url({{(user.avatar!=null)?user.avatar:'/img/general_user.svg'}})" style="width:200px;height:200px"></div>

If user do not have any image, user.avatar comes null. 如果用户没有任何图像,则user.avatar为空。

In Chrome works fine but not in IE 11. What's wrong? 在Chrome中可以正常运行,但在IE 11中则不能。这是怎么回事?

Try using ng-style, which exists for this purpose. 尝试使用为此目的而存在的ng-style。

https://docs.angularjs.org/api/ng/directive/ngStyle 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>

(not tested) (未测试)

您应该执行以下操作:

<div class="dashboard_image" ng-style="{'background-image': user.avatar!=null ? 'url(user.avatar)' : 'url(/img/general_user.svg)'" style="width:200px;height:200px"></div>

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

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