I have a service that returns image URL, and it is called using the following code:
angular.forEach(results, function (item) {
item.img = "/images/searchItem.jpg";
$http.post("https://my.api.com/?id=" + item.id).success(
function (url) {
item.img = url;
});
});
on my view I used to have an image with ng-src attribute, that worked perfectly like so:
<img ng-src="{{item.img}}">
Then I've decided to use background-image on a SPAN instead:
<span ng-style="{'background':'transparent url({{item.img}})'}"></span>
now the flow works only on the first run, after that I can see (in the console) the following html
<span ng-style="{'background':'transparent url(http://expertsimages.liveperson.com/images/rating/rate10.gif)'}" style="background-image: url(https://fb.lp-chat.com/images/searchItem.jpg); background-color: transparent; background-position: initial initial; background-repeat: initial initial;"></span>
which indicates that the variable updated, however the html is still on its initial state.
I tried to call apply/digest on post success, but got an error $digest already in progress (which make sense). The strage thing is that after a normal digest (for example on other ui changes) the style is being applied and I see the right image.
What am I missing here?
Update: I've created a JS fiddle that demonstrates this issue...looks like a bug in angular to me.