在打印前隐藏页码 - 骁勇表

问题描述 投票:0回答:1

我有一个父组件 比尔 带打印按钮

<button class="btn btn-primary" type="button" (click)="printBill()"> Print </button>

和一个子组件 账单产品 列表

<p-table [value]="products" [loading]="loading" [paginator]="allowPaginator" [rows]="1">

我想隐藏分页器,当客户点击打印按钮时,显示所有产品。

printBill() {
    this.allowPaginator = false;
    window.print();
  } 

但是发生的情况是在打印文档后而不是在打印前隐藏分页器。

有什么建议吗?

angular typescript
1个回答
1
投票

你可以尝试延迟一点 window.print(). 在angular变化检测发生更新视图之前,它正在运行。试试这个。

printBill() {
  this.allowPaginator = false;
  setTimeout(() => window.print(), 300);
} 

我感觉你甚至不需要这个东西 300ms 值:只要把 window.print() 在事件循环中队列的开始处,在当前循环结束后进行处理。

printBill() {
  this.allowPaginator = false;
  setTimeout(() => window.print());
} 
© www.soinside.com 2019 - 2024. All rights reserved.