Image of item list with directive

I found this way you can load an image to each list item. Leo RSS and rescue from there the image corresponding to each story, the problem is that some of these do not come with rss image then do an if follows

.directive('backImg', function($timeout,$rootScope){
return function(scope, element, attrs){

$timeout(function () {
  var content = element.find('a');
  for (var i = 0; i < $rootScope.entries.length; i++) {
      imagen = $rootScope.entries[i].img;
      if(typeof imagen === "undefined"){
        content.css({
          'background-image': 'url(img/app-entel.png)',
          'background-size' : 'cover',
          'height' : '100px'
        });
      }else{
        //console.log(imagen);
        content.css({
        'background-image': 'url('+imagen+')',
        'background-size' : 'cover',
        'height' : '100px'
      });
    }
  };
  });
 };
})

The problem is that when printing to the console the url of the image is all good, but the list always loads the default image I have in the event that the travel arrangement image comes as undefined and do not understand why.