Angular 7 - 如何路由到新的窗口位置或文件
创始人
2024-10-16 15:31:52
0

要在Angular 7中实现路由到新的窗口位置或文件,您可以使用window.open()方法。以下是一个示例代码:

  1. 在组件中导入RouterLocation
import { Router, Location } from '@angular/router';
  1. 在构造函数中注入RouterLocation
constructor(private router: Router, private location: Location) { }
  1. 创建一个方法来处理路由到新窗口的逻辑:
openNewWindow(url: string) {
  window.open(url, '_blank');
}
  1. 在需要路由到新窗口的地方调用该方法:
this.openNewWindow('/new-page');

完整的示例代码:

import { Component } from '@angular/core';
import { Router, Location } from '@angular/router';

@Component({
  selector: 'app',
  template: `
    
  `
})
export class AppComponent {
  constructor(private router: Router, private location: Location) { }

  openNewWindow(url: string) {
    window.open(url, '_blank');
  }
}

请注意,为了能够使用window.open()方法,您的应用必须在浏览器环境中运行,而不是在服务端渲染或其他非浏览器环境中。

希望对您有所帮助!

相关内容

热门资讯

记者揭秘!德普之星辅助工具如何... 记者揭秘!德普之星辅助工具如何设置,hhpoker德州真的假的,揭秘教程(有挂软件)1、很好的工具软...
盘点一款!pokemmo手机脚... 盘点一款!pokemmo手机脚本辅助器,wepoker有辅助功能吗,解密教程(有挂辅助);建议优先通...
解密关于!wepoker辅助是... 1、解密关于!wepoker辅助是真的吗,wpk辅助器,AI教程(有挂技巧)。2、wepoker辅助...
推荐攻略!we-poker辅助... 推荐攻略!we-poker辅助,hhpoker有后台操作吗,切实教程(有挂辅助)关于hhpoker有...
每日必备!pokemmo手机版... 每日必备!pokemmo手机版透视脚本,wpk辅助器,透明教程(有挂神器);建议优先通过pokemm...
一分钟揭秘!hhpoker是正... 《一分钟揭秘!hhpoker是正规的吗,wepoker怎么挂底牌,玩家教你(有挂透明)》 hhpok...
我来教教大家!wepoker看... 我来教教大家!wepoker看底牌,约局吧德州可以透视吗,揭秘攻略(有挂透视)1、不需要AI权限,帮...
记者揭秘!epoker透视底牌... 记者揭秘!epoker透视底牌,大菠萝辅助器,2025教程(有挂方法);玩家必备必赢加哟《13670...
教程攻略!pokemmo辅助器... 1、教程攻略!pokemmo辅助器手机版下载,智星德州插件2024最新版,玩家教程(有挂技巧)2、进...
玩家交流!hhpoker必备开... 玩家交流!hhpoker必备开挂,wepoker有没有辅助,微扑克教程(有挂攻略);1分钟了解详细教...