Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add [routerLink] from component?

My html call to this component

   <navbar [title]="'Recorridos'"
            [hasNavbarItems]="true"
            [itemsJsonFileName]="'recorrido-list-navbar-items.json'"
            (btnActionClicked)="onBtnActionClicked($event)"
            (btnFilterClicked)="onBtnFilterClicked($event)">
    </navbar>

this is a dynamic component then in onBtnActionClicked($event) needs to redirect like

<a [routerLink]="['/parent/detail', detail.detailId]">{{detail.detailId}}</a>

but as you see this can't be added from html then in my component I could call the button click doing

onBtnActionClickedV(event) {

        }

in that function how can I redirect like routerLink does??

like image 812
angel Avatar asked Dec 14 '22 03:12

angel


1 Answers

Have you tried something like this....

onBtnActionClickedV(event) {
   this.router.navigate(['/parent/detail']);
    }

and make sure you import router i.e.

import { Router }          from '@angular/router';
like image 194
Bean0341 Avatar answered Dec 18 '22 11:12

Bean0341