我有删除报告的功能,这是我的代码
public deleteCustomReport(dataItem): void {
var scheduleNames = this.getScheduleNames(dataItem.id);
this.confirmDelete(scheduleNames, dataItem);
}
函数this.getScheduleNames(dataItem.id)
是异步函数,我需要在this.confirmDelete(scheduleNames, dataItem)
之前调用它才能使我的代码正常工作。现在,它会在this.getScheduleNames(dataItem.id)
之后调用this.confirmDelete(scheduleNames, dataItem)
并且var scheduleNames
不会发现。
以下是this.confirmDelete(scheduleNames, dataItem)
功能
private confirmDelete(scheduleNames, dataItem): void {
var confirmDeletion = angular.copy(this.constantService.confirmDeleteSwalSettings);
if (scheduleNames != null) {
confirmDeletion.text = "Are you sure you want to delete " + dataItem.name + " report?";
}
else {
confirmDeletion.text = "This report is in schedual. Are you sure you want to delete " + dataItem.name + " report?";
}
this.sweetAlert.swal(confirmDeletion, (isConfirm) => {
if (isConfirm) {
this.reportsService.deleteCustomReport(dataItem.id)
.then(data => {
this.getReports();
});
}
});
}
和this.getScheduleNames(dataItem.id)
private getScheduleNames(id): string {
var name = "";
this.reportsService.checkIfReportIsInSchedule(id)
.then(data => {
name = data;
});
return name;
}