使用变量写入txt文件

rcarcia02

在我的 Angular 程序中,我希望能够单击一个按钮,然后打开一个显示该月报告或摘要的窗口,并且已成功执行此操作,但由于某种原因我无法包含变量。每当Report for date {{monthlyEndDate}}我的 html 文本中内容时,它都会在不使用绑定的情况下准确打印出来。我怎样才能做到这一点?

这是我的 .ts 文件,我的按钮只是调用printMonthlyReport()函数:

import { Component, OnInit } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { EmpInfo } from './emp-info';
import { EmpInfoService } from './emp-info.service';
import { PTOData } from './pto-data';
import { PTODataService } from './pto-data.service';

@Component({
    selector: 'pto-report',
    templateUrl: `./report.component.html`,
    styleUrls: ['./report.component.css']
})

export class ReportComponent {

    date = new Date();
    monthlyStartDate = new Date(this.date.getFullYear(), this.date.getMonth(), 1);
    monthlyEndDate = new Date(this.date.getFullYear(), this.date.getMonth() + 1, 0);
    
    printMonthlyReport(): void {
        let popupWin;
        popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
        popupWin.document.open();
        popupWin.document.write(`
          <html>
            <head>
              <title>Monthly PTO/ETO Report</title>
            </head>
            <body>
              <h3>Monthly PTO/ETO Payroll Report {{monthlyEndDate}}</h3>
            </body>
          </html>
`)
    }
}

保尔·克鲁伊特

你应该使用

`bla bla ${this.fieldName} bla bla`

因此,使用 访问字段变量this,并将变量包装${}在模板字符串 (``) 中

popupWin.document.write(`
      <html>
        <head>
          <title>Monthly PTO/ETO Report</title>
        </head>
        <body>
          <h3>Monthly PTO/ETO Payroll Report ${this.monthlyEndDate}</h3>
        </body>
      </html>
`)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章