Angular2 dynamic background images

In the html template, I have this style with a dynamic image:

<div style="background: url('/img/{{item.img}}'); width: 200px; height: 150px"></div>

What works in browsers and the Android browser. However, background images that are dynamic using "style =" are not displayed on the iPad.

I could always create dynamic images using the img tag, but I am looking for a / css style solution for the iPad.

+4
source share
2 answers

Use instead

<div [ngStyle]="{background: 'url(/img/' + item.img + ')', width: '200px', height: '150px'"></div>

or

<div [style.background]="'url(/img/' + item.img + ')'"
    [style.width.px]="200" [style.height.px]="150p"></div>

See also In RC.1, some styles cannot be added using binding syntax.

+29
source

, + Günter Zöchbauer : : Safari .

, :

<div [style.background-image]="'url(/img/' + item.img + ')'"
 [style.width.px]="200" [style.height.px]="150p"></div>
+2

All Articles