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

后端 未结 8 1133
一整个雨季
一整个雨季 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 20:54

    Just for the records you can also define your object in the controller like this:

    this.styleDiv = {color: '', backgroundColor:'', backgroundImage : '' };
    

    and then you can define a function to change the property of the object directly:

    this.changeBackgroundImage = function (){
            this.styleDiv.backgroundImage = 'url('+this.backgroundImage+')';
        }
    

    Doing it in that way you can modify dinamicaly your style.

提交回复
热议问题