Skip to content

Instantly share code, notes, and snippets.

@mizrael
Created June 24, 2015 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizrael/a7c61674ca5e05672710 to your computer and use it in GitHub Desktop.
Save mizrael/a7c61674ca5e05672710 to your computer and use it in GitHub Desktop.
AngularJS directive with function (and arguments)
myApp.directive('callbackDirective', function () {
return {
scope: {
callback: '&'
},
restrict: 'E',
templateUrl: 'my-template.html'
controller: ['$scope', function ($scope) {
$scope.foo = function (bar) {
if ($scope.callback) {
$scope.callback({value: bar});
}
};
}]
}
})
<callback-directive callback="myCallback(value)" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment