1

My click event:

html:
 <div class="image"   (click)="onClickOperation(product);">
.......
</div>
TS:
onClickOperation(product: any): void {
    // debugger
    if (this.regularView) {
      if (this.details) {
        this.openLightbox(product);
      } else {
        this.router.navigate(['/product', product.productId]);
      }
    } else {
      this.router.navigate(['/store', product.shopId]);
      this.productsender.changeMessage(product);
    }
  }

its working fine how I want to implement right click to open link in new tab option .how can I do it need

  • 1
    Does this answer your question? [Angular 2 Routing navigate run in new tab(Use Angular Router naviagte )](https://stackoverflow.com/questions/50521494/angular-2-routing-navigate-run-in-new-tabuse-angular-router-naviagte), [Angular 2 Routing run in new tab](https://stackoverflow.com/q/41355830/8017690) – Yong Shun Feb 09 '22 at 06:13
  • 1
    What do you mean, right-click to open a new link? did you mean left to on the button? – HassanMoin Feb 09 '22 at 06:17
  • right click to open in new tab option @HassanMoin – Noob in Angualr Feb 09 '22 at 11:41

1 Answers1

4

If you mean you want to be able to open the link via the right-click menu then you need to pass routerLink to the a tag. There is the solution: How to enable "ctrl+click" with "routerLink" in Angular

And an example:

<a routerLink="/user/bob">link to user component</a>

or

<a [routerLink]="['/user/jim']">Jim</a>

You need "a" tag because in HTML only this tag has the property to open links by HTML functionality.

Information on how to use routerLink you can find in angular routerLink docs

In your case probably you should use *ngIf make a condition to display a correct element with the correct URL.

There is an example of how to make it. Conditionally add RouterLink or other attribute directives to an element in Angular 2

If you want to replace the context menu with your function, just look at this issue: How to handle right click event in Angular app?

Kordrad
  • 1,154
  • 7
  • 18