How to open a link in new tab using angular?

后端 未结 9 1471
温柔的废话
温柔的废话 2020-12-08 13:03

I have an angular 5 component that needs to open a link in new tab, I tried the following:

page link

        
相关标签:
9条回答
  • 2020-12-08 13:26

    In the app-routing.modules.ts file:

    {
        path: 'hero/:id', component: HeroComponent
    }
    

    In the component.html file:

    target="_blank" [routerLink]="['/hero', '/sachin']"
    
    0 讨论(0)
  • 2020-12-08 13:29

    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>
    
    0 讨论(0)
  • 2020-12-08 13:32

    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");
    }
    
    0 讨论(0)
提交回复
热议问题