如何在角度5的新标签页中打开链接 [英] How to open link in new tab in angular 5

查看:83
本文介绍了如何在角度5的新标签页中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个angular 5组件,需要在新标签页中打开链接,我尝试了以下操作:

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

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

当我打开链接时,应用程序变慢并打开如下路径:

when I open the link, the application gets slow and opens a route like:

localhost:4200/www.example.com

我的问题是:
用角度进行此操作的正确方法是什么?

My question is: What is the correct way to do this in angular?

推荐答案

使用 window.open()。非常简单!

在您的 component.html 文件中-

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

在您的 component.ts 文件中-

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

这篇关于如何在角度5的新标签页中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆