Angular 2-重定向到外部URL并在新标签页中打开 [英] Angular 2 - Redirect to an external URL and open in a new tab
本文介绍了Angular 2-重定向到外部URL并在新标签页中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户单击链接时,我正在尝试打开一个新页面.我不能使用Angular 2 Router,因为它没有任何功能可以重定向到外部URL.
I'm trying to Open a new page when user clicks on a link. I can't use Angular 2 Router, because it doesn't have any functionalities to redirect to an external URL.
所以,我正在使用window.location.href ="...";
so, i'm using window.location.href="...";
html代码:
<button (click)="onNavigate()">Google</tn-submenu-link>
打字稿代码:
onNavigate(){
//this.router.navigateByUrl("https://www.google.com");
window.location.href="https://www.google.com";
}
但是如何在新标签页中打开它?使用window.location.href时?
But how can I open it in a new tab? when using window.location.href ?
推荐答案
onNavigate(){
window.open("https://www.google.com", "_blank");
}
这篇关于Angular 2-重定向到外部URL并在新标签页中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文