1

In this issue, first time it is coming into else block where downloadCsv method is getting called then rather destroy the component is again comes into if block. Somehow subscription has made twice in this method. How can we reduce that? Is there any way in rootscope to identify the number of request?

public $onInit() {
if (
      this.type === CsvDownloadTypes.ANY ||
      this.type === CsvDownloadTypes.GLOBAL_USER ||
      this.type === CsvDownloadTypes.USER
    ) {
      const listener =  this.$rootScope.$on('csv-download-request', (_event, options) => {
        console.log("event..",_event);

          this.FILENAME = options.filename || this.FILENAME;
          if (this.CsvDownloadService.downloadInProgress) {
            console.log("if block");
            this.Notification.error('csvDownload.isRunning');
          } else {
            // start export
            console.log("else block");
            this.downloadCsv(options.csvType);
          }
        });
        this.eventListeners.push(listener);
        console.log("scopr..", angular.element().scope)
        console.log("scope 2..", this.$rootScope);
    }

    // see if there is a current active download, and set out flag
    this.downloading = this.CsvDownloadService.downloadInProgress;
    this.eventListeners.push(
      this.$rootScope.$on('csv-download-request-completed', (): void => {
        this.downloading = this.CsvDownloadService.downloadInProgress;
      })
    );
  }
}

Destroy part

 public $onDestroy() {
    while (!_.isEmpty(this.eventListeners)) {
      console.log("EventListneronDestroy");
      _.attempt(this.eventListeners.pop());
    }
  }

0 Answers0