如何使用angular在新标签页中打开链接? [英] How to open a link in new tab using angular?

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

问题描述

我有一个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");
}

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

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