angularjs ng-style doesn't work on background

2019-09-05 04:27发布

问题:

On another thread I got the information that the background can be set dynamically by using mg-style. Unfortunately I can't get it work.

syntax like this:

ng-style="{'background-image':'url(https://www.google.com/images/srpr/logo4w.png)'}"

I have a fiddle for testing: fiddle

fiddle:

<ion-item class="item-icon-right item-avatar defaultItem" data-ng-repeat="item in items " data-ng-style="{'background-image':'url({{item.url}})'}">

The background-image of the ion-item should be set to the mg-style element.

回答1:

Seen elsewhere (Ionic Forums - credit to maxx0r) : don't use ng-style but style instead. That has worked for me. So your example should change as follows:

<ion-item class="item-icon-right item-avatar defaultItem" data-ng-repeat="item in items " style="background-image:url({{item.url}})">

HTH, best regards.