How to disable right-click event in Angular 7?

I'm trying to disable that menu that appears on the page when the user right-clicks.

In Angular, I can catch the click event using (click)="onRightClick($event), but I only catch the "Left Click" in $event.

Remembering that if I do HostListener('click') myClick(){ } it's the same thing as (click)="myClick()

I searched the documentation for Angular and @ HostListener and didn't find a solution.

@HostListener documentation Link: Angular - HostListener

This is the code where I catch the click event, but it only catches the Left Click, when it is the Right Click, the code is not triggered.

@HostListener('click', ['$event'])
  onClick(event) {
    console.log(event);
  }
Author: Edward Ramos, 2019-06-21

1 answers

The (click) as well as the parameter 'click' in @HostListener will execute as addEventListner, the click event works even only with the left click, if you want to make more iterations with the mouse you must use mousedown, example:

@HostListener('mousedown', ['$event'])
teste(event: MouseEvent)
{
    switch (event.button) {
        case 1:
            console.log('Botão esquerdo do mouse! ');
            break;
        case 2:
            console.log('Botão direito do mouse! ');
            break;
        default:
            console.log('Outro botão de mouse (click no scroll, mouse gamer, etc)');
    }
}
 2
Author: Guilherme Nascimento, 2019-06-21 17:44:15