toastr.service.d.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { ComponentRef, Injector, NgZone } from '@angular/core';
  2. import { DomSanitizer } from '@angular/platform-browser';
  3. import { Observable } from 'rxjs';
  4. import { Overlay } from '../overlay/overlay';
  5. import { ToastRef } from './toast-injector';
  6. import { ToastContainerDirective } from './toast.directive';
  7. import { GlobalConfig, IndividualConfig, ToastToken } from './toastr-config';
  8. export interface ActiveToast<C> {
  9. /** Your Toast ID. Use this to close it individually */
  10. toastId: number;
  11. /** the message of your toast. Stored to prevent duplicates */
  12. message: string;
  13. /** a reference to the component see portal.ts */
  14. portal: ComponentRef<C>;
  15. /** a reference to your toast */
  16. toastRef: ToastRef<C>;
  17. /** triggered when toast is active */
  18. onShown: Observable<any>;
  19. /** triggered when toast is destroyed */
  20. onHidden: Observable<any>;
  21. /** triggered on toast click */
  22. onTap: Observable<any>;
  23. /** available for your use in custom toast */
  24. onAction: Observable<any>;
  25. }
  26. export declare class ToastrService {
  27. private overlay;
  28. private _injector;
  29. private sanitizer;
  30. private ngZone;
  31. toastrConfig: GlobalConfig;
  32. currentlyActive: number;
  33. toasts: ActiveToast<any>[];
  34. overlayContainer: ToastContainerDirective;
  35. previousToastMessage: string | undefined;
  36. private index;
  37. constructor(token: ToastToken, overlay: Overlay, _injector: Injector, sanitizer: DomSanitizer, ngZone: NgZone);
  38. /** show toast */
  39. show(message?: string, title?: string, override?: Partial<IndividualConfig>, type?: string): ActiveToast<any>;
  40. /** show successful toast */
  41. success(message?: string, title?: string, override?: Partial<IndividualConfig>): ActiveToast<any>;
  42. /** show error toast */
  43. error(message?: string, title?: string, override?: Partial<IndividualConfig>): ActiveToast<any>;
  44. /** show info toast */
  45. info(message?: string, title?: string, override?: Partial<IndividualConfig>): ActiveToast<any>;
  46. /** show warning toast */
  47. warning(message?: string, title?: string, override?: Partial<IndividualConfig>): ActiveToast<any>;
  48. /**
  49. * Remove all or a single toast by id
  50. */
  51. clear(toastId?: number): void;
  52. /**
  53. * Remove and destroy a single toast by id
  54. */
  55. remove(toastId: number): boolean;
  56. /**
  57. * Determines if toast message is already shown
  58. */
  59. findDuplicate(message: string, resetOnDuplicate: boolean, countDuplicates: boolean): ActiveToast<any>;
  60. /** create a clone of global config and apply individual settings */
  61. private applyConfig;
  62. /**
  63. * Find toast object by id
  64. */
  65. private _findToast;
  66. /**
  67. * Determines the need to run inside angular's zone then builds the toast
  68. */
  69. private _preBuildNotification;
  70. /**
  71. * Creates and attaches toast data to component
  72. * returns the active toast, or in case preventDuplicates is enabled the original/non-duplicate active toast.
  73. */
  74. private _buildNotification;
  75. }