角度:将变量传递给window.open(); [英] Angular: Pass variables to window.open();

查看:79
本文介绍了角度:将变量传递给window.open();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Angular中打开一个新选项卡,该选项卡根本没有任何功能.它只是显示数据供用户打印的选项卡.我的问题是,在主应用程序中,我打电话来获取数据,但是当我打开新选项卡时,变量不保存主应用程序中的数据.变量将被重置,就好像它是Angular应用程序的新实例一样.

I would like to open a new tab in Angular that won't have any functions at all. It is only a tab to display data for a user to print. My problem is that in the main app I do a call to get the data, but when I open the new tab, the variables don't hold the data from the main app. The variables are reset as if it is a new instance of the Angular app.

我通过执行以下操作来创建新标签:

I create a new tab by doing the following:

window.open('#/print-report');

然后在我的应用程序模块中,上述路线打开PrintReportComponent:

Then in my app modules the above route opens the PrintReportComponent:

{ path: 'print-report', component: PrintReportComponent},

但是在新选项卡中,应用程序启动时,程序中的每个变量都将重置为其默认值.如何将任何变量保存"或传递"到这个新标签页?

But in the new tab, every variable throughout my program is reset to its default value when the app starts up. How do I "save" or "pass" any variables to this new tab?

推荐答案

您可以尝试执行以下操作:

You can try something like this:

要打印报告:

  /**
   * Method is used to print report.
   * @param response - html response.
   */
  printReport(response) {

    let data = response;

    let Pagelink = "about:blank";

    let pwa = window.open(Pagelink, "_new");

    if (!pwa || pwa.closed || typeof pwa.closed == 'undefined') {

      alert('Pop-up!', 'Please disable your Pop-up blocker and try again.', 'warning');

    }

    pwa.document.open();

    pwa.document.write(data);

    pwa.print();

  }

要下载报告:

    /**
     * Method is use to download file.
     * @param data - Array Buffer data
     * @param type - type of the document.
     */
    downLoadFile(data: any, type: string) {
        var blob = new Blob([data], { type: type.toString() });
        var url = window.URL.createObjectURL(blob);
        window.open(url);
    }

这篇关于角度:将变量传递给window.open();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆