Angular:
http://angularjs.org/
by gavinfoley
HTML
<div ng-controller="MyCtrl">
<button ng-click="call()" >Call</button>
<div id="container" my-directive cb="setDirectiveFn(fn)"></div>
</div>
JavaScript
var app = angular.module('myApp',[]);
app.directive("myDirective", function() {
return {
scope: { cb: '&' },
controller: function($scope) {
$scope.myfn = function() {
console.log("myfn called");
}
$scope.cb({fn: $scope.myfn});
}
};
});
function MyCtrl($scope) {
$scope.call = function() {
$scope.directiveFunction();
};
$scope.setDirectiveFn = function(directiveFn) {
$scope.directiveFunction = directiveFn;
};
}