Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build a dynamic URL on anchor tag click - Angular 5

I have a table of several anchor tags. I want to create an external URL dynamically on clicking each anchor tag. I tried using [routerLink] but it is getting the base URL appended. Is there any angular way of doing it ? Any help is much appreciated.

html

<ng-container matColumnDef="invoiceNo">
          <mat-header-cell *matHeaderCellDef > Invoice # </mat-header-cell>
          <mat-cell *matCellDef="let invoice"> 
            <a [routerLink]="getInvoiceUrl()"  target="_blank">
              {{invoice.invoiceNumber}}
            </a>
          </mat-cell>
        </ng-container>

ts

 getInvoiceUrl(){

return "www.google.com";

}

like image 937
DJ4186 Avatar asked Oct 24 '25 21:10

DJ4186


2 Answers

yes, just use href:

<a [href]="getInvoiceUrl()">

Make sure you include http: else it will include the domain.

so:

return "http://www.google.com";
like image 81
David Anthony Acosta Avatar answered Oct 27 '25 17:10

David Anthony Acosta


public link="public"

use this in a tag --> [href]=link> {{ link }}

It will redirect to www.localhost:4200/public

like image 31
Hemant Vetal Avatar answered Oct 27 '25 18:10

Hemant Vetal