button router link angular code example
Example 1: add a route to a buttoin in angular
<button type="button" class="btn btn-primary-outline pull-right" (click)="btnClick();"><i class="fa fa-plus"></i> Add</button>
import { Router } from '@angular/router';
constructor(private router: Router) {
}
btnClick= function () {
this.router.navigateByUrl('/user');
};
Example 2: call a function whenever routerlink is clicke angular
<a class="nav-link" [routerLink]="['/home']" (click)="doSomeLogic()">Home</a>
Example 3: routerlink for button in angular 7
<a routerLink="/">Go To Home</a>