Angular: call controller function from directive (controller)

http://angularjs.org/

by wwwroot

HTML

<div ng-controller="MyCtrl">
  <confirm callback="shout"></confirm>
</div>

JavaScript

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

app.directive('confirm', function($parse) {
  return {
    restrict: 'E',
    scope: {
      callback: "="
    },
    controller: ['$scope', function($scope) {
      this.click = function() {
      alert('wweaasd');
        console.log($scope.callback);
        $scope.callback("hello from controller!");
      }
    }],
    controllerAs: "ctrl",
    template: '<button ng-click="ctrl.click()">Click me</button>'
  };
});

app.controller('MyCtrl', MyCtrl);

function MyCtrl($scope) {
  $scope.shout = function() {
    alert('hi')
  };
}