Angular - method-directive

http://stackoverflow.com/questions/17556703/angularjs-directive-call-function-specified-in-attribute-and-pass-an-argument-to/17570515#17570515

by Guruprasad Gopalkrishna

HTML

<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-app="myApp">
<div ng-controller="myController">
    <div my-method='theMethodToBeCalled'>Click me</div>
</div>
</div>

JavaScript

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

app.directive("myMethod", function($parse) {
   var directiveDefinitionObject = {
     restrict: 'A',
       replace : true,
       controller : function($scope) {
       $scope.selectNode = function(data){
           debugger;
           var method = $scope.method();
           method(data);
          //$scope.method.apply([data]); 
    };
    },
       template : '<div ng-click="selectNode(123)">CLick me!</div>',
     scope: {
         method:'&myMethod'
     },
     link: function(scope,element,attrs) {
         
        var expressionHandler = scope.method();
        var id = "123";

        
     }
   };
   return directiveDefinitionObject;
});

app.controller("myController",function($scope) {
  $scope.theMethodToBeCalled = function(id) { 
      console.log(id); 
      alert(id);
  };
});