0

I have 4 tabs, on click of each tab, if it is active then it is highlighted. But to one tab i had used (click) event, so i am unable to make that tab active. So can anyone help me how can i make that active on click of that function.

HTML:

<a  id="AminManage" class="list-group-item justify-content-between" (click)="patientinfo()"  routerLinkActive="active">
  <span>
    <i class="icon-home"></i>Patient Information</span>
</a>

I also used [routerLink]="['/admin/patient-info/', Cookie.get('AdminPatientId')]" but didnt work.

Here this is not supporting routerLinkActive="active" so is there anyway to make it work. Please help.

Ts:

patientinfo(){
    this.router.navigate(['/admin/patient-info', Cookie.get('AdminPatientId')])
  }
Bhrungarajni
  • 2,415
  • 11
  • 44
  • 88

2 Answers2

0

Inside the patientinfo() function, you can write the logic to add routerLinkActive="active" on the anchor tag.

I hope this will help you.

Abhishek Sharma
  • 360
  • 1
  • 10
  • hai thanks for response, but here if i add active class, then it will be highlighted all time, but i want that to get highlighted only when i click on that tab – Bhrungarajni Jun 29 '18 at 08:29
  • You needn't to write class="active" statically on HTML, instead you will write a logic inside the patientinfo() function to add class to anchor tag, after the anchor has been clicked. – Abhishek Sharma Jun 29 '18 at 09:41
  • can you please show how? should i write inside this? patientinfo() – Bhrungarajni Jun 29 '18 at 10:43
  • check this please https://stackoverflow.com/questions/42809368/angular-2-adding-a-class-to-a-dom-element-when-clicked – Abhishek Sharma Jun 29 '18 at 17:01