button onclick redirect to another page in new tab angular 8 code example

Example 1: how click button and redirect angular

<a class="btn" routerLink="/votes">Check votes</a>

Example 2: how click button and redirect angular

import { Component } from '@angular/core';
import { Router } from '@angular/router';
// component details here...
export class MyComponent  {
  constructor(private router: Router){ }

  goToVotes($myParam: string = ''): void {
    const navigationDetails: string[] = ['/votes'];
    if($myParam.length) {
      navigationDetails.push($myParam);
    }
    this.router.navigate(navigationDetails);
  }
}

Tags:

Html Example