如何在Angular 6中用中键单击鼠标在新选项卡中打开routerlink? 我想在新标签页中打开每个链接。 例如
<button mat-icon-button color="accent" [routerLink]="['/edit', a.Id]">
<mat-icon>edit</mat-icon>
</button>
答案 0 :(得分:4)
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);
}
}
答案 1 :(得分:0)
<a (click)="open(a.Id,$event)" href="/edit/{{item.Id}}" target="_blank">
<mat-icon>edit</mat-icon>
</a>
然后
open(id: number, event: MouseEvent) {
// prevent href to fire.
// href will work only for middle mouse button click
event.preventDefault();
// open in new tab when click + ctrl
if (event.ctrlKey) {
return window.open('/edit/' + id, '_blank')
}
this.router.navigate(['/userAd', id]);
}