Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Middle click mouse in Angular 6

Tags:

angular

How to open routerlinks in a new tab with middle click mouse in Angular 6? I want to open every link in a new tab. for example

<button mat-icon-button color="accent" [routerLink]="['/edit', a.Id]"> <mat-icon>edit</mat-icon> </button>

like image 220
Alex Avatar asked Jul 25 '18 02:07

Alex


1 Answers

The auxclick event is fired when a any non-left mouse button has been pressed and released on an element.

<button mat-icon-button color="accent" [routerLink]="['/edit', a.Id]" 
  (auxclick)="onClick($event)">
          <mat-icon>edit</mat-icon>
</button>

component.ts

onClick(e){
   e.preventDefault();
   if(e.which==2){
     window.open('/users/'+a.Id);
   }

}
like image 188
Chellappan வ Avatar answered Nov 15 '22 08:11

Chellappan வ