directive with controller in angular

Developer from somewhere

Been trying to get a directive to use a controller method. I had this:

app.directive "myDirective", ->
  restrict: "A"
  controller: ($scope) ->
    sayHello: ->
      alert "Hello"
  template: '<div><a ng-click="sayHello()">Say hello</a></div>'

And it wouldn’t react. The problem was that the method had to be dined on the scope:

app.directive "myDirective", ->
  restrict: "A"
  controller: ($scope) ->
    $scope.sayHello = ->
      alert "Hello"
  template: '<div><a ng-click="sayHello()">Say hello</a></div>'