Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
How to make a link inside element with router link in Angular 2

I need to make router link on a div element but also inside it add another anchor or button that opens menu. Because of router link menu cannot be opened. Clicking on a button fires router link. How can I make it work?

<div [routerLink]="/foo">
    <span>Title</span>
    <button (click)="openMenu()">Open menu</button>
</div>

Actually I am using Angular Material and in fact the problem looks like this:

<md-card [routerLink]="/foo">
    <span>Title</span>

    <button md-icon-button [mdMenuTriggerFor]="menu">
      <md-icon>more_vert</md-icon>
    </button>

    <md-menu #menu="mdMenu">
      <button md-menu-item (click)="rename()">
        <md-icon>create</md-icon>
        <span>Rename</span>
      </button>
      <button md-menu-item (click)="share()">
        <md-icon>share</md-icon>
        <span>Share</span>
      </button>
    </md-menu>
</md-card>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

try below,

<button md-icon-button [mdMenuTriggerFor]="menu" (click)="open($event)" >
  <md-icon>more_vert</md-icon>
</button>

in corresponding ts file,

open(e){
  // this will stop event to propagate to work on link click.
  e.stopPropagation();
}

Hope this helps!!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!