How can I handle the Angular (click) event for the middle mouse button?

Thimo

I have an icon that acts as a link to open an URL. When a user clicks on that link I need to make an API call and some other actions.

Now clicking with the left button aswell as Ctrl + Click triggers the method fine. Only when opening the link with the middle mouse click, the method gets not fired.

<a [href]="'somelink.com' + someVariable" target="_blank" (click)="someMethod('some', 'params')">
    <div class="some-icon">
        <img src="/assets/icon/icon.svg" height="54" alt="Icon" />
    </div>
</a>

Is there another way to call a method in my Component on middle click?

ConnorsFan

For secondary mouse buttons, you can handle the auxclick event. In the following example, the click event is triggered by the primary mouse button, and the auxclick event is triggered by the other mouse buttons.

<a (click)="onClick($event)" (auxclick)="onAuxClick($event)">...</a>
onClick(event: MouseEvent) {
  console.log("click - button", event.button, event.which);
}

onAuxClick(event: MouseEvent) {
  console.log("auxclick - button", event.button, event.which);
}

See this stackblitz for a demo. Please note that the same method can handle both events. I call different methods in the demo to show which event is handled.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to handle middle mouse click?

How do i trigger the mouse middle button in enter event of the mouse?

How do I map the middle mouse button to make a double click?

How do I disable middle mouse button click paste?

How do I disable the middle mouse button click?

How to correctly handle right click mouse event for a button

How can I distinguish wheel button click event from mouse press event?

Middle mouse click emulation on trackpad, how can I set it?

How to detect middle mouse button click?

How can I delete a record (that is selected by mouse) from a datasheet using a Delete button On Click Event?

How can I change the alt+middle-mouse-button resize to alt+right-mouse-button?

Middle button click event

How can i get mouse click event element in cocoa

How can I call the mouse right click event in SwingGui?

Catching a middle mouse button click in an Angular 6 directive

How to use middle mouse button (or center click) to scroll in Okular?

How to handle Xamarin Camera Button Click Event

How can I set the Synaptics TouchPad's hardware right-click button to middle click?

Can I tell emacs to paste (middle mouse button) on the cursor position?

How can I pass my list to button click event?

How can I intercept the tweet button click event?

How can I click a button to launch an ItemSelected event of spinner control?

How can I set the click event to disabled when draggable a button?

How can I make a call on button click event in Xamarin

how can I call partial view from button click event

How can i toggle the same button click event for two cases?

How to handle right click event in Angular app?

How to handle long click event in angular for mobile?

Disable mouse scroll middle click event with jQuery