Angular对话框打开会导致新加载的页面上的查询参数被删除。
创始人
2024-10-24 15:31:18
0

在打开对话框之前,使用Angular的Location一些API附加查询参数。例如,可以使用以下代码:

import { Component } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Router, ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
export class YourComponent {
  constructor(
    private dialog: MatDialog,
    private router: Router,
    private route: ActivatedRoute
  ) {}

  openDialog(): void {
    // 获取当前查询参数
    let queryParams = this.route.snapshot.queryParams;
    // 打开对话框之前将当前查询参数附加到URL中
    this.router.navigate([], {
      relativeTo: this.route,
      queryParams: queryParams,
      queryParamsHandling: 'merge'
    });
    // 打开对话框
    const dialogRef = this.dialog.open(YourDialogComponent, {
      width: '250px'
    });
  }
}

这将在打开对话框之前将当前查询参数附加到URL中,并使用“merge”选项将它们与现有查询参数合并。这样,即使在加载对话框期间页面重新加载,查询参数也会被保留。

相关内容

热门资讯

辅助透视!wepoker破解器... 辅助透视!wepoker破解器激活码,wepoker透视脚本免费使用视频(透视)玩家教程(有挂工具)...
透视计算!we-poker辅助... 透视计算!we-poker辅助,wepoker免费透视(透视)攻略教程(有挂脚本)在进入wepoke...
透视安装!wepoker有没有... 透视安装!wepoker有没有辅助,wepoker插件辅助(透视)细节方法(有挂教程)1、首先打开w...
辅助透视!wejoker内置辅... 辅助透视!wejoker内置辅助,we-poker辅助器(透视)揭秘教程(有挂工具)1、该软件可以轻...
透视肯定!wepoker有没有... 透视肯定!wepoker有没有透视方法,wepoker好友房开挂(透视)力荐教程(有挂黑科技)1)w...
透视模拟器!wepoker怎么... 透视模拟器!wepoker怎么买辅助,wepoker私人局规律(透视)切实教程(有挂细节)1、让任何...
透视脚本!wepoker俱乐部... 透视脚本!wepoker俱乐部辅助,淘宝买wepoker透视有用吗(透视)解密教程(有挂解说)1)淘...
透视挂透视!wepoker透视... 透视挂透视!wepoker透视器免费,wepoker透视破解版(透视)揭秘教程(有挂详情);1、下载...
透视实锤!wepoker怎么设... 透视实锤!wepoker怎么设置房间,we-poker是什么软件(透视)靠谱教程(有挂详情);wep...
透视免费!wepoker私人局... 透视免费!wepoker私人局辅助挂,we-poker辅助软件教程(透视)透明挂教程(有挂解密)1、...