Skip to content

Instantly share code, notes, and snippets.

@tastywheat
Last active December 28, 2015 06:19
Show Gist options
  • Save tastywheat/7456397 to your computer and use it in GitHub Desktop.
Save tastywheat/7456397 to your computer and use it in GitHub Desktop.
angular - call controller method via directive attribute
.controller( 'AboutCtrl', function AboutCtrl( $scope ) {
$scope.doWork = function(){
alert('working');
};
})
.directive('stinky', function(){
return {
link: function($scope, $element, $attributes, $compile){
$element.bind("click", function(){
$scope.$apply($attributes.stinky);
});
}
};
})
//<span stinky="doWork()">click me</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment