domoindal
domoindal

Reputation: 1533

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.

In Chrome works fine but not in IE 11. What's wrong?

Upvotes: 2

Views: 218

Answers (2)

Zdenek Hatak
Zdenek Hatak

Reputation: 1145

Try using ng-style, which exists for this purpose.

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)

Upvotes: 3

Jarri
Jarri

Reputation: 1

You should do something like this:

<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>

Upvotes: 0

Related Questions