0

All:

RIght now, I need to load some image into page, for each image, if I right click on it, it will show a tooltip of its info such as size and description. I implement the image as a directive, but I do not know how to handle the right click correctly, any suggestion for best practice( any example is appreciated)?

Thanks

Kuan
  • 11,149
  • 23
  • 93
  • 201
  • 1
    possible duplicate of [How do I handle right-click events in angular.js?](http://stackoverflow.com/questions/15731634/how-do-i-handle-right-click-events-in-angular-js) – Donal May 17 '15 at 17:48
  • @Donal Thanks, I am gonna try this. – Kuan May 17 '15 at 18:01

1 Answers1

1

If you already have a directive for the images, you should be able just to do the following in the link function of your directive:

link:function(scope, elem){
    elem.bind('contextmenu', function(ev) {
        ev.preventDefault();
        alert('success!'); //Show tooltip here
    });
}
Dylan Watt
  • 3,357
  • 12
  • 16
  • thanks, I think my crucial question should be how to structure that tooltip directive( should I add tooltip into each image directive structure or make a seperated tooltip directive? ) and how to manage its behavior or event responds – Kuan May 17 '15 at 18:01
  • It depends on the tooltip. Is it a very specific tooltip to one type of component(directive)? If so, make it part of the directive. If you intend to use the same tooltip for many different situations, I'd make a specific `tooltip` directive which you use by decorating other elements. You could use how https://angular-ui.github.io/bootstrap/#/tooltip is implemented for a good pattern. – Dylan Watt May 17 '15 at 18:04
  • thanks, it is the first case. I guess then I just need to figure out the style issue. – Kuan May 18 '15 at 15:48
  • Also, as an aside, showing a tooltip on rightclick might be nonintuitive. What if they wanted to right click -> save as? Tooltips make more sense as a mouseover. – Dylan Watt May 18 '15 at 19:51
  • thanks, my bad, I should call it right click menu rather than tooltip, but it is just a name, we know what I mean. – Kuan May 18 '15 at 20:18