angular - Angular 在新选项卡中使用参数打开新组件
问题描述
经过一番研究,我发现没有办法直接用角度来实现这一点。
所以,我尝试了一种不同的解决方案,我在这里找到了但没有人工作
这是我试图实现这一目标的实现:
在路由中,我为新组件添加了路由:
{
path: "popout/:id",
component: MetricsComponent,
canActivate: [AuthenticationGuard]
}
在我的 html 中,我只有一个调用方法的按钮:
<button target="_blank" class="action-button hvr-float-shadow" mat-mini-fab
(click)="openGraphWindow()">
<mat-icon class="action-icon" svgIcon="METRIC" style="fill: black"></mat-icon>
</button>
在 ts 文件中:
public openGraphWindow() {
// this.router.navigate(['popout', this.selectedAsset.id]);
window.open(this.router.url+`/popout/${this.selectedAsset.id}`, '_blank');
}
当我点击按钮时,我得到了这个:
无法获取 /home/detail/popout/37897
所以,在点击之前,网址是: http://localhost:4200/myapp/#/home/detail
当我点击打开新标签时,出现的网址是: http://localhost:4200/home/detail/popout/37897
如您所见,并非 url 的所有部分都被注入,我也尝试过:
window.location.href 而不是 this.router.url
但生成相同的网址
那么如何使用参数在新选项卡中打开新组件?
我尝试过的另一个解决方案是将标签 a 与 routerLink 一起使用,但结果相同
有关信息,我正在使用 Angular 8
感谢您的帮助
解决方案
推荐阅读
- rust - 有没有办法制作结构,包含内部引用?
- makefile - 带有模式和通配符的 Makefile:没有规则来制作目标
- python - 如何读取 JSON 格式的日语词典列表而不插入新字符?
- java - 如何同时更新和删除数据 Realtime Firebase
- c# - C# 正确使用带有 SafeSocketHandle 的 Dispose
- java - 过滤firebase中的子数据
- exchange-basicauth - 为 IMAP 添加 Oauth2 支持的时间表
- python - 从 docx 中提取文本作为键值对给出属性错误
- python - 忽略python单元测试用例中的记录器功能
- c - 如何在 C 中的数组中保存和显示元素