How to open a link in new tab using angular? How to open a link in new tab using angular? angular angular

How to open a link in new tab using angular?


Use window.open(). It's pretty straightforward !

In your component.html file-

<a (click)="goToLink("www.example.com")">page link</a>

In your component.ts file-

goToLink(url: string){    window.open(url, "_blank");}


just use the full url as href like this:

<a href="https://www.example.com/" target="_blank">page link</a>


<a [routerLink]="" (click)="openSite(SiteUrl)">{{SiteUrl}}</a>

and in your Component.ts

openSite(siteUrl) {   window.open("//" + siteUrl, '_blank');}