当用户单击链接时,我正在尝试打开一个新页面。我不能使用 Angular 2 路由器,因为它没有任何功能可以重定向到外部 URL。
所以,我正在使用 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 时?
原文由 Varun 发布,翻译遵循 CC BY-SA 4.0 许可协议
为了更全面地解决这个问题,这里有另一种使用 指令 的方法:
那么它就像这样使用它一样简单:
并且不要忘记在你的模块中声明指令。