File

src/app/shared/services/toast.service.ts

Description

Toast Service

Index

Properties
Methods

Methods

remove
remove(toast)
Parameters :
Name Optional
toast No
Returns : void
show
show(textOrTpl: string | TemplateRef, options: any)
Parameters :
Name Type Optional Default value
textOrTpl string | TemplateRef<any> No
options any No {}
Returns : void
showError
showError(message: string, args: object)
Parameters :
Name Type Optional Default value
message string No
args object No { classname: 'bg-danger text-light', delay: 2000 , autohide: true, }
Returns : void
showSuccess
showSuccess(message: string, args: object)
Parameters :
Name Type Optional Default value
message string No
args object No { classname: 'bg-success text-light', delay: 2000 , autohide: true }
Returns : void

Properties

toasts
Type : any[]
Default value : []
import {Injectable, TemplateRef} from '@angular/core';

/**
 * Toast Service
 */
@Injectable({
  providedIn: 'root'
})
export class ToastService {
  toasts: any[] = [];

  show(textOrTpl: string | TemplateRef<any>, options: any = {}) {
    this.toasts.push({ textOrTpl, ...options });
  }

  remove(toast) {
    this.toasts = this.toasts.filter(t => t !== toast);
  }

  showSuccess(message: string,
              args = {
                classname: 'bg-success text-light',
                delay: 2000 ,
                autohide: true
              }) {
    this.show(message, args);
  }

  showError(
    message: string,
    args = {
      classname: 'bg-danger text-light',
      delay: 2000 ,
      autohide: true,
    }) {
    this.show(message, args);
  }

  // showCustomToast(customTpl) {
  //   this.show(customTpl, {
  //     classname: 'bg-info text-light',
  //     delay: 3000,
  //     autohide: true
  //   });
  // }
}

result-matching ""

    No results matching ""