File

projects/lib/src/utils/toast/toast.service.ts

Index

Properties
Methods

Methods

hide
hide()
Returns : void
show
show(message: string, style: BsStyle | string, actions?: ToastAction[], options?: Toast.Options)
Parameters :
Name Type Optional Default value
message string No
style BsStyle | string No 'info'
actions ToastAction[] Yes
options Toast.Options Yes
Returns : void

Properties

onToastMessage
Default value : new Subject<ToastMessage|null>()
import { Injectable } from '@angular/core';
import { Toast } from 'bootstrap';
import { Subject } from 'rxjs';

export type BsStyle = 'info' | 'success' | 'warning' | 'danger' | 'primary' | 'secondary' | 'light' | 'dark';

export interface ToastAction {
  text?: string;
  style?: string | string;
  icon?: string;
  hideToast?: boolean;
  action: () => void;
}

export interface ToastMessage {
  icon?: string;
  message: string;
  style?: BsStyle | string;
  actions?: ToastAction[];
  options?: Toast.Options;
}

@Injectable({providedIn: 'root'})
export class ToastService {

  onToastMessage = new Subject<ToastMessage|null>();

  show(
    message: string,
    style: BsStyle | string = 'info',
    actions?: ToastAction[],
    options?: Toast.Options
  ) {
    this.onToastMessage.next({message, style, actions, options});
  }

  hide() {
    this.onToastMessage.next(null);
  }

}

results matching ""

    No results matching ""