How do I handle right-click events in angular.js?
angularjs
Solution
You can use a directive to bind specific action on right click, using the `contextmenu` event :
app.directive('ngRightClick', function($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});
});
});
};
});
Code example on fiddle
Problem
Is there a way to have an element set up so that it performs one action on left-click (ng-click) and then another action on a right-click? Right now I have something like: ``` <span ng-click="increment()">{{getPointsSpent()}}</span> ``` And I'd like to also be able to right click on the span to perform the function decrement();