How to handle the Angular (click) event of the middle mouse button?


Timo

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

Clicking with the left button as well as Ctrl+Click now triggers the method nicely. The method doesn't fire only when the middle mouse button is clicked to open the link.

<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 a Component when the middle mouse button is clicked?

Connors Fan

For auxiliary mouse buttons, you can handle the auxclick event. In the following example, the event is fired clickby the primary mouse button , and the event is fired by the other mouse buttons.auxclick

<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 stack blitz for a demo . Note that the same method can handle both events. I call different methods in the demo to show the events to be handled.

Related


How to handle the middle mouse button?

Gibbs I have an ember component that generates a set of user groups. When the user clicks on one of the list components, it calls the linkAction defined in that component and takes the user to the specific page associated with that list item. However, when the

How to handle the middle mouse button?

Gibbs I have an ember component that generates a set of user groups. When the user clicks on one of the list components, it calls the linkAction defined in that component and takes the user to the specific page associated with that list item. However, when the

How to handle the middle mouse button?

Gibbs I have an ember component that generates a set of user groups. When the user clicks on one of the list components, it calls the linkAction defined in that component and takes the user to the specific page associated with that list item. However, when the

How to handle the middle mouse button?

Gibbs I have an ember component that generates a set of user groups. When the user clicks on one of the list components, it calls the linkAction defined in that component and takes the user to the specific page associated with that list item. However, when the

How to properly handle button's right click mouse event

Reza I want to handle mouse right click event for button. I wrote the following code; mybutton.onmousedown = e => { e.preventDefault(); const mouseEvent = { 0: () => leftClickCallback, 2: () => rightClickCallback } mouseEvent[

How to properly handle button's right click mouse event

Reza I want to handle mouse right click event for button. I wrote the following code; mybutton.onmousedown = e => { e.preventDefault(); const mouseEvent = { 0: () => leftClickCallback, 2: () => rightClickCallback } mouseEvent[

How to map the middle mouse button for double click?

Kira Ubuntu 18.04. When I click the middle mouse button, it should double click. thanks. Edit: Using the Unity desktop. unknown OS: Ubuntu 18:04 Required packages: xdotoolandxbindkeys you can install these packagessudo apt install xdotool xbindkeys gedit .xbin

How to disable middle mouse button click?

hardcode My mouse is faulty and the middle mouse button is always pressed, but I don't know how to disable the click function. I've looked at the mouse settings, but I can't change the function of the middle mouse button at all. I still want to be able to scro

How to detect middle mouse button click?

Nate All the questions I've seen about how to detect the middle mouse button in JavaScript are related to jQuery, but I would like to know how to use regular JavaScript to detect a middle mouse button click. I tried using onClick(), but it only seems to work w

How to detect middle mouse button click?

Nate All the questions I've seen about how to detect the middle mouse button in JavaScript are related to jQuery, but I would like to know how to use regular JavaScript to detect a middle mouse button click. I tried using onClick(), but it only seems to work w

How to detect middle mouse button click?

Nate All the questions I've seen about how to detect the middle mouse button in JavaScript are related to jQuery, but I would like to know how to use regular JavaScript to detect a middle mouse button click. I tried using onClick(), but it only seems to work w

How to disable middle mouse button click?

hardcode My mouse is faulty and the middle mouse button is always pressed, but I don't know how to disable the click function. I've looked at the mouse settings, but I can't change the function of the middle mouse button at all. I still want to be able to scro

How to detect middle mouse button click?

Nate All the questions I've seen about how to detect the middle mouse button in JavaScript are related to jQuery, but I would like to know how to use regular JavaScript to detect a middle mouse button click. I tried using onClick(), but it only seems to work w

How to handle button click event in jQuery?

Ahmad Farid | I need to have a button and handle its events in jQuery. And I'm writing this code and it's not working. What did I miss? <!-- Begin Button --> <div class="demo"> <br> <br> <br> <input id = "btnSubmit" type="submit" value="Release"/> <br> <b

How to handle Xamarin camera button click event

Surab Somani Right now I'm creating a Xamarin app and I'm using the camera to log in. The application works fine as follows: var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { }); The a

How to handle button click event in jQuery?

Ahmad Farid | I need to have a button and handle its events in jQuery. And I'm writing this code and it's not working. What did I miss? <!-- Begin Button --> <div class="demo"> <br> <br> <br> <input id = "btnSubmit" type="submit" value="Release"/> <br> <b

How to handle button click event in meteor?

blue change I have a meteor template: <template name="createDefaultTemplate"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> Select Role of router</h4> </div> <div class="btn-gro

How to handle click event in bootstrap button dropdown

username Change event in bootstrap button dropdown doesn't work. What could be the reason? how to solve this problem? Below is my fiddle. I want to fire the checkbox change event, but surprisingly, the following code doesn't fire. http://jsfiddle.net/20hLtzvr/

How to handle button click event in meteor?

blue change I have a meteor template: <template name="createDefaultTemplate"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> Select Role of router</h4> </div> <div class="btn-gro

How to handle button click event in jQuery?

Ahmad Farid | I need to have a button and handle its events in jQuery. And I'm writing this code and it's not working. What did I miss? <!-- Begin Button --> <div class="demo"> <br> <br> <br> <input id = "btnSubmit" type="submit" value="Release"/> <br> <b

How to handle right click event in Angular app?

Rolando: In Angular, is there a way to capture the right click event? I see (click) and (dblclick) but when I try (right click) it doesn't fire any events. Is there a way to include right click events and handle them with functions similar to click and dblclic

How to handle right click event in Angular app?

Rolando: In Angular, is there a way to capture the right click event? I see (click) and (dblclick) but when I try (right click) it doesn't fire any events. Is there a way to include right click events and handle them with functions similar to click and dblclic

Disable mouse wheel middle click event with jQuery

Natsu: I wrote the code below to disable scrolling on mouse while clicking on it. But when i scroll with my mouse it opens my link click my code is not working. Here is my code: $('a').on('mousedown', function(e) { if (e.which === 2) { console.log('Disab

Disable mouse wheel middle click event with jQuery

Natsu: I wrote the code below to disable scrolling on mouse while clicking on it. But when i scroll with my mouse it opens my link click my code is not working. Here is my code: $('a').on('mousedown', function(e) { if (e.which === 2) { console.log('Disab