如何使用 angular 在新标签页中打开链接? [英] How to open a link in new tab using angular?
本文介绍了如何使用 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屋!
查看全文