0

Sorry to ask for suck seemingly easy question, but I really don't know how to handle it and I can't make it work. I have this directive which recieves data from a $broadcast, which then has to use to create a new template.

  app.directive('emptyScope', function() {
    return function( $scope ) {
       return $scope.$on('checkEmptyArray', function(event, data) {
          return {
            template: '<img src="../images/apple.png">'
          };
      });
    }
});

The data from 'checkEmptyArray' comes in perfectly, and through console.log I can see that indeed, it recieved the data. But for some reason, it doesn't do the

return  {
            template: '<img src="../images/apple.png">'
          };

I don't understand why it isn't doing it. Does someone have any clue? Thanks.

Alan
  • 1

1 Answers1

0

You can't return anything because it's a callback. You'll need to render your image within your function.

app.directive('emptyScope', function() {
    return function( $scope ) {
       return $scope.$on('checkEmptyArray', function(event, data) {
          $scope.myImg = data;
      });
    }
});


 <div ng-bind-html="myImg"></div>
NovaPenguin
  • 463
  • 3
  • 8