同步通话

时间:2017-03-22 06:15:40

标签: javascript angular typescript observable

我想从服务器下载文件后删除该文件,但是即使我把它放在下载文件行下面这是我的代码,服务中的delete方法也会先执行:

generateClearanceExcel(): void {
    if (this.selectedIds.length > 0) {
        var departureDate = prompt("Please enter departure date.", "");
        if (departureDate !== null && departureDate !== "") {
            this.generating = true;
            this.clearanceService.generateClearanceExcel(this.selectedIds, departureDate).subscribe(
                result => {
                    this.generating = false;
                    window.location.href = "clearance/downloadreport/?fileName=" + result.fileName;
                    this.clearanceService.deleteFile(result.fileName).subscribe();

                    if (result.success == true) {
                        if (result.infos.length > 0) {
                            this.alertService.info(result.infos);
                        }
                    }
                    else {
                        this.alertService.error(result.errors);
                    }
                }
            );
        }
    }
}

TIA。

2 个答案:

答案 0 :(得分:1)

让我们尝试超时

generateClearanceExcel(): void {
    if (this.selectedIds.length > 0) {
        var departureDate = prompt("Please enter departure date.", "");
        if (departureDate !== null && departureDate !== "") {
            this.generating = true;
            this.clearanceService.generateClearanceExcel(this.selectedIds, departureDate).subscribe(
                result => {
                    this.generating = false;
                    window.location.href = "clearance/downloadreport/?fileName=" + result.fileName;
                     setTimeout(() => {
                      this.clearanceService.deleteFile(result.fileName).subscribe();
                    }, 3000);
                    setTimeout(function(){  }, 3000);                       

                    if (result.success == true) {
                        if (result.infos.length > 0) {
                            this.alertService.info(result.infos);
                        }
                    }
                    else {
                        this.alertService.error(result.errors);
                    }
                }
            );
        }
    }
}

答案 1 :(得分:0)

您应该将删除方法置于下载成功的条件下。

Pattern pattern = Pattern.compile("(\\d+)(\\s)([-+*%/^])(\\s)(\\d+)");
Matcher matchOp1 = pattern.matcher(text);
matchOp1.find();
System.out.println(matchOp1.group(1));