简体   繁体   English

angular 应该在新窗口中打开链接

[英]angular should open the link in new window

how to open below route in new window.如何在新窗口中打开下面的路线。 I want this route which is for recorder component to open in new window我希望这条用于recorder组件的路由在新窗口中打开

  closeDialog(requestType) {
    this.dialogRef.close();
    this.router.navigate(["recorder"], { state: { example: requestType } });
  }

router.navigate is to navigate in the same window. router.navigate 是在同一个窗口中导航。 You need to use window.open to open a new tab:您需要使用window.open打开一个新选项卡:

closeDialog(requestType) {
    this.dialogRef.close();
    window.open(`${window.origin}/recorder?exampe=${requestType}`, '_blank');
}

Update更新

You need to specify the third parameter in the window.open method to open a completely new window:你需要在 window.open 方法中指定第三个参数来打开一个全新的窗口:

closeDialog(requestType) {
    this.dialogRef.close();
    window.open(`${window.origin}/recorder?exampe=${requestType}`, '_blank', 'width=1024,height=768');
}

Similar answer here:类似的答案在这里:

JavaScript open in a new window, not tab JavaScript 在新窗口中打开,而不是选项卡

You can still use the Angular Router and use .then您仍然可以使用Angular Router并使用.then

    closeDialog(requestType: any) {
    this.dialogRef.close();
    const link = `${window.origin}/recorder?exampe=${requestType}`;
    this.router.navigate(["recorder"], { state: { example: requestType } }).then((result: any) => {  window.open(link, '_blank'); });
  }

I added the Angular Router link below fit you'd like to see what other cool stuff it can do.我在下面添加了 Angular Router 链接,你想看看它还能做什么其他很酷的事情。

In keeping with the other answers the link should be whatever you declared - so in the example your link was what I placed, I just type checked it in vs code so I believe this should work.为了与其他答案保持一致,链接应该是您声明的任何内容 - 因此在示例中,您的链接是我放置的内容,我只是在 vs 代码中键入检查它,所以我相信这应该有效。 https://angular.io/guide/router https://angular.io/guide/router

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM