Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
<logger fn="log(msg)"></logger>
</div>
JavaScript
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.name = 'Superhero';
$scope.log = function(msg) {
alert(msg);
}
}
myApp.directive('logger', function() {
return {
restrict: "EA",
scope: {
fn: '&'
},
template: '<button ng-click="logit()">logback</button>',
link: function(scope, element, attrs) {
scope.logit = function() {
scope.fn({msg: "test"});
};
}
}
});