0

I want to change background image on body element using angular js dynamically. I am trying to do this as mentioned below:

<body ng-style="{'background-image':'url({{vm.img}})'}">

Where vm.img is set from the controller, but I am not able to change the image accordingly.

etee
  • 86
  • 6

2 Answers2

0

you can add style in your body element

<body style = "background-image:'url({{backgroundImage}})';background-size: cover;"></body>
byteC0de
  • 5,153
  • 5
  • 33
  • 66
  • That doesn't work either, I am not getting the value from the interpolation, as there is no controller associated to it. Is there any other way to set my background image dynamically. – etee Apr 28 '16 at 04:52
0

It's a kind of hacky solution. I used resolve in ui-router which resolved the data before controller gets loaded, added the img to the rootScope and modified the code below and voila!!

<body ng-style="{'background-image':'url(' + img +')'}">
etee
  • 86
  • 6