File

src/app/user-notify/user-notify.service.ts

Description

This service provides functions for user notification

Index

Methods

Constructor

constructor(toastr: ToastrService)
Parameters :
Name Type Optional
toastr ToastrService No

Methods

notifyError
notifyError(message: string, error?: Error)

Notify the user that an error occurred

Parameters :
Name Type Optional Description
message string No

The message to be shown

error Error Yes

Optionally, the error. This will be logged in the console, if defined.

Returns : void
notifyInfo
notifyInfo(message: string)

Notify the user

Parameters :
Name Type Optional Description
message string No

The message to be shown

Returns : void
import {Injectable} from '@angular/core';
import {IndividualConfig, ToastrService} from 'ngx-toastr';

/**
 * This service provides functions for user notification
 */
@Injectable({providedIn: 'root'})
export class UserNotifyService {
  /** @ignore */
  private errorConfig: Partial<IndividualConfig> = {
    timeOut: 10000,
    closeButton: true,
    positionClass: 'toast-top-center',
    enableHtml: true
  };

  /** @ignore */
  private infoConfig: Partial<IndividualConfig> = {
    timeOut: 4000,
    closeButton: true,
    positionClass: 'toast-top-center',
    enableHtml: true
  };

  constructor(private toastr: ToastrService) {}

  /**
   * Notify the user that an error occurred
   * @param message The message to be shown
   * @param error Optionally, the error. This will be logged in the console, if defined.
   */
  notifyError(message: string, error?: Error): void {
    if (error !== undefined) {
      console.error('Error:', error);
    }

    this.toastr.error(message, 'Error!', this.errorConfig);
  }

  /**
   * Notify the user
   * @param message The message to be shown
   */
  notifyInfo(message: string): void {
    this.toastr.info(message, 'Info', this.infoConfig);
  }
}

results matching ""

    No results matching ""