flauc / angular2-notifications

A light and easy to use notifications library for Angular.
https://stackblitz.com/edit/angular2-notifications-example
MIT License
746 stars 164 forks source link

dynamically change content. #321

Open BoJIbFbI4 opened 6 years ago

BoJIbFbI4 commented 6 years ago

it's possible to dynamically change content. For example: catch the file size and show it in %. with existing code, i get a new notification for every kb.

 toast(req: any, fileName: string) {
    this.form = this._fb.group({
      type: 'success',
      timeOut: 1000,
      showProgressBar: true,
      pauseOnHover: true,
      clickToClose: true,
      animate: 'fromRight'
    });

    this.http.request(req).subscribe((event: HttpEvent<any>) => {
      switch (event.type) {
        case HttpEventType.Sent:
          const toastStart = this.form.getRawValue();
          this.notificationService.success(`Downloading ${fileName}`, `Download is started! `, toastStart);
          delete toastStart.type;
          break;
        case HttpEventType.ResponseHeader:
          break;
        case HttpEventType.DownloadProgress:
          this.size = (event.total / 1048576).toFixed(2);
          break;
        case HttpEventType.Response:
          const toastDone = this.form.getRawValue();
          toastDone.showProgressBar = false;
          this.notificationService.success(`Downloading ${fileName}`, `Download is finished! ${this.size} Mb loaded`, toastDone);
          saveAs(event.body, fileName);
      }
    });
  }
BoJIbFbI4 commented 5 years ago

what's new?