I am using Angular.JS version 1.1.5 and I am using the following code I found on stackoverflow to change the background-image of a div:
angular.module('app', [])
.directive('ng-background', function(){
return function(scope, element, attrs){
var url = attrs['ng-background'];
element.css({
'background-image': 'url(' + url +')',
'background-size' : 'cover'
});
};
});
Then, in my HTML, I have the following (jade template)
html(ng-app)
div(ng-controller='myCtrl')
div.big-image(ng-background='{{flags.imgSrc}}')
Now, please consider that flags.imgSrc does work and returns a correct image URL, as I have previously tested it with an img(ng-src='{{flags.imgSrc}}').
The problem with this is that it does not seem to work at all! I have tried to put a console.log('test') inside my directive but it does not seem to called. Any ideas why? Thanks in advance.