File

src/lib/service/notifications/notifications.service.ts

Description

Wrapper for Toastr Service

Index

Methods

Constructor

constructor(toastrService: ToastrService)
Parameters :
Name Type Optional
toastrService ToastrService no

Methods

confirm
confirm(title: string, msg?: string, onAdd?: any, onRemove?: any)

Show confirm colored massage (blue)

Parameters :
Name Type Optional
title string no
msg string yes
onAdd any yes
onRemove any yes
Returns : void
error
error(title: string, msg?: string, onActivateTick: )

Show error colored massage (red)

Parameters :
Name Type Optional Default value Description
title string no

title

msg string yes

msg

onActivateTick no false

onActivateTick

Returns : void
info
info(title: string, msg?: string)

Show info colored massage (blue)

Parameters :
Name Type Optional
title string no
msg string yes
Returns : void
success
success(title: string, msg?: string)

Show success colored massage (green)

Parameters :
Name Type Optional
title string no
msg string yes
Returns : void
wait
wait(title: string, msg?: string)

can not be in use

Parameters :
Name Type Optional
title string no
msg string yes
Returns : void
warning
warning(title: string, msg?: string)

Show warning colored massage (yellow)

Parameters :
Name Type Optional
title string no
msg string yes
Returns : void

notifications.service

import {Injectable} from '@angular/core';
import { ToastrService } from 'ngx-toastr';

/**
 * Wrapper for Toastr Service
 */
@Injectable({
  providedIn: 'root'
})
export class NotificationsService {

  /**
   * Default Notofication Options
   *
   */
  private options: any = {
    closeButton: true,
    positionClass: 'toast-bottom-right',
    timeOut: 15000
  };

  constructor(private toastrService: ToastrService) {
  }

  /**
   * Show info colored massage (blue)
   *
   * @param string title
   * @param string msg
   */
  info(title: string, msg?: string) {
    this.toast(title, msg);
  }

  /**
   * Show confirm colored massage (blue)
   *
   * @param string title
   * @param string msg
   * @param onAdd
   * @param onRemove
   */
  confirm(title: string, msg?: string, onAdd?: any, onRemove?: any) {
    this.toast(title, msg, 'confirm', {onAdd, onRemove, timeOut: 7000});
  }

  /**
   * Show success colored massage (green)
   * @param string title
   * @param string msg
   */
  success(title: string, msg?: string) {
    this.toast(title, msg, 'success');
  }

  /**
   * can not be in use
   *
   * @param string title
   * @param string msg
   */
  wait(title: string, msg?: string) {
    this.toast(title, msg, 'wait');
  }

  /**
   * Show error colored massage (red)
   *
   * @param title title
   * @param msg msg
   * @param onActivateTick onActivateTick
   */
  error(title: string, msg?: string, onActivateTick = false) {
    this.toast(title, msg, 'error', {
      closeButton: true,
      timeOut: 7000,
      onActivateTick
    });
  }

  /**
   * Show warning colored massage (yellow)
   *
   * @param string title
   * @param string msg
   */
  warning(title: string, msg?: string) {
    this.toast(title, msg, 'warning');
  }

  /**
   * Public wrapper for accessing the Toastr
   *
   * @param string title
   * @param string msg
   * @param string mode
   * @param _options
   */
  private toast(title: string, msg: string, mode?: string, _options?: {}) {
    let options: any = Object.assign({}, this.options, _options);
    // options.title = title || '';
    // options.msg = msg || '';
    this.doToast(msg, title, options, mode);
  }

  /**
   * Accessing the toastr service
   *
   * @param string msg
   * @param string title
   * @param options
   * @param string mode
   */
  private doToast(msg: string, title: string, options: any, mode?: string) {
    switch (mode) {
      case 'success': {
        this.toastrService.success(msg, title, options);
        break;
      }
      // case 'wait': {
      //   this.toastrService.wait(msg, title, options);
      //   break;
      // }
      case 'error': {
        this.toastrService.error(msg, title, options);
        break;
      }
      case 'warning': {
        this.toastrService.warning(msg, title, options);
        break;
      }
      case 'confirm': {
        this.toastrService.info(msg, title, options);
        break;
      }
      default: {
        this.toastrService.info(msg, title, options);
      }
    }
  }
}

results matching ""

    No results matching ""