Skip to content

Instantly share code, notes, and snippets.

@carbonrobot
Created October 15, 2014 19:29
Show Gist options
  • Save carbonrobot/162255ca69e6d61f00bf to your computer and use it in GitHub Desktop.
Save carbonrobot/162255ca69e6d61f00bf to your computer and use it in GitHub Desktop.
Angular Right Click Directive
(function () {
/*
* @name ngRightClick
* @type Directive
* @desc Binds the right click to a javascript function by using the ng-right-click attribute
*/
function ngRightClick($parse) {
return function (scope, element, attrs) {
var fn = $parse(attrs.ngRightClick);
element.bind('contextmenu', function (event) {
scope.$apply(function () {
event.preventDefault();
fn(scope, { $event: event });
});
});
};
}
ngRightClick.$inject = ['$parse'];
angular.module('app').directive('ngRightClick', ngRightClick);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment