Test scope access in directive

by Achim Sperling

HTML

<div ng-controller="UserController">
    Hello, {{profile.name}}!
    <div profile-image email="profile.email" avatar="profile.avatar"></div>
</div>

JavaScript

var myApp = angular.module('myApp',[]);

myApp.directive('profileImage', [
  function profileImageDirective() {
    return {
      restrict: 'A',
      replace: true,
      scope: {
        email: '=email',
        avatar: '=avatar'
      },
      link: function(scope, ele, attrs) {
        console.log(scope);
      },
      controller: ['$scope', function ($scope) {
      
      }],
      template: '<img alt="" ng-src="{{image}}" class="img-circle">'
    };
  }]);

myApp.controller('UserController', ['$scope', 
  function($scope) {
      $scope.profile = {
          name: 'Superhero',
          email: '[email protected]',
          avatar: '/images/avatar.jpg'
      };
  }]);