0

I have a funtion for deleting reports, here is my code

public deleteCustomReport(dataItem): void {
      var scheduleNames = this.getScheduleNames(dataItem.id);      

      this.confirmDelete(scheduleNames, dataItem);
    }

Function this.getScheduleNames(dataItem.id) is async function and I need to call it before this.confirmDelete(scheduleNames, dataItem) for my code to work. Right now it calls this.getScheduleNames(dataItem.id) after this.confirmDelete(scheduleNames, dataItem) and var scheduleNames is left undefind.

Here is my code for this.confirmDelete(scheduleNames, dataItem) function

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();
            });
        }
      });
    }

and for this.getScheduleNames(dataItem.id)

private getScheduleNames(id): string {
      var name = "";

      this.reportsService.checkIfReportIsInSchedule(id)
        .then(data => {
          name = data;
        });

      return name;
    }
Grill
  • 31
  • 3

0 Answers0