I have an angular 5 component that needs to open a link in new tab, I tried the following:
page link
In the app-routing.modules.ts
file:
{
path: 'hero/:id', component: HeroComponent
}
In the component.html
file:
target="_blank" [routerLink]="['/hero', '/sachin']"
Just add target="_blank"
to the
<a mat-raised-button target="_blank" [routerLink]="['/find-post/post', post.postID]"
class="theme-btn bg-grey white-text mx-2 mb-2">
Open in New Window
</a>
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");
}