angularjs ng-style: background-image isn't working

后端 未结 8 1098
一整个雨季
一整个雨季 2020-12-12 20:38

I\'m trying to apply a background image to a div by using the angular ng-style ( I tried a custom directive before with the same behaviour ), but it doesn\'t se

相关标签:
8条回答
  • 2020-12-12 21:01

    It is possible to parse dynamic values in a couple of way.

    Interpolation with double-curly braces:

    ng-style="{'background-image':'url({{myBackgroundUrl}})'}"
    

    String concatenation:

    ng-style="{'background-image': 'url(' + myBackgroundUrl + ')'}"
    

    ES6 template literals:

    ng-style="{'background-image': `url(${myBackgroundUrl})`}"
    
    0 讨论(0)
  • The syntax is changed for Angular 2 and above:

    [ngStyle]="{'background-image': 'url(path)'}"
    
    0 讨论(0)
提交回复
热议问题