【发布时间】:2019-12-10 05:18:23
【问题描述】:
我有一个应用程序,其中网页需要显示进度条,同时网站从多个 API 获取数据并构建 pdf 文档。这里我使用jsPDF 构建 pdf。我在模板中使用了以下实现。
<div class="col-md-2 col-sm-2">
<mat-progress-bar mode="indeterminate" [value]="progressValue" *ngIf="isPrintinginProgress"></mat-progress-bar>
<Button class="btn btn-primary" style="align: right" (click)="printSelected()">Print Selected</Button></div>
isPrintinginProgress 变量在开始时被初始化以隐藏元素,并在 printSelected() 函数中更新为 true 以显示元素。
import {Component, OnInit} from '@angular/core';
import * as jsPDF from 'jspdf';
export class PrintViewComponent implements OnInit {
printList: PrintPendingOrderModel[];
isPrintinginProgress = false;
dataSource = new MatTableDataSource<PrintPendingOrderModel>(this.printList);
selection = new SelectionModel<PrintPendingOrderModel>(true, []);
constructor(private apiService: ApisService,
private utilService: UtilsService) { }
ngOnInit() {
}
printSelected() {
this.isPrintinginProgress = true; //showing up the progressbar
const doc = new jsPDF();
console.log('printing page:', page_no);
if (page_no < total_pages) {
console.log('end page:', page_no);
doc.addPage();
} else {
doc.autoPrint({variant: 'non-conform'});
window.open(doc.output('bloburl'), '_blank').focus();
console.log('Print Complete');
this.isPrintinginProgress = false; //hiding up the progressbar
}
this.selection.clear();
}
} }
如果我将 isPrintinginProgress 初始化为 true,进度条会显示在开头,但 isPrintinginProgress 变量中的值更改不会反映在使用 *ngif(show/hide) 的元素功能中
【问题讨论】:
-
看起来它可能会在控制台中抛出错误,停止执行将其设置为 false。尝试将错误条件放在 else 块的开头。
-
只能在else条件下运行吗,你能检查一下吗?
-
控制台有什么错误吗?
-
控制台中没有错误。是的,它仅在 printSelected() 方法中执行。并且更改为起跑台并没有做出任何改变
-
如果我评论 this.isPrintinginProgress = false;新窗口打开后显示进度条,构建的pdf,可能是jsPdf阻塞了模板中的更改?
标签: angular typescript angular-material jspdf