New: Headless Commerce with Remix! read more

NotificationService

NotificationService

Provides toast notification functionality.

Example

class MyComponent {
  constructor(private notificationService: NotificationService) {}

  save() {
    this.notificationService
        .success(_('asset.notify-create-assets-success'), {
          count: successCount,
        });
  }
}

## Signature

```TypeScript
class NotificationService {
  constructor(i18nService: I18nService, resolver: ComponentFactoryResolver, overlayHostService: OverlayHostService)
  success(message: string, translationVars?: { [key: string]: string | number }) => void;
  info(message: string, translationVars?: { [key: string]: string | number }) => void;
  warning(message: string, translationVars?: { [key: string]: string | number }) => void;
  error(message: string, translationVars?: { [key: string]: string | number }) => void;
  notify(config: ToastConfig) => void;
}

Members

constructor

method
type:
(i18nService: I18nService, resolver: ComponentFactoryResolver, overlayHostService: OverlayHostService) => NotificationService

success

method
type:
(message: string, translationVars?: { [key: string]: string | number }) => void
Display a success toast notification

info

method
type:
(message: string, translationVars?: { [key: string]: string | number }) => void
Display an info toast notification

warning

method
type:
(message: string, translationVars?: { [key: string]: string | number }) => void
Display a warning toast notification

error

method
type:
(message: string, translationVars?: { [key: string]: string | number }) => void
Display an error toast notification

notify

method
type:
(config: ToastConfig) => void
Display a toast notification.

NotificationType

The types of notification available.

Signature

type NotificationType = 'info' | 'success' | 'error' | 'warning'

ToastConfig

Configuration for a toast notification.

Signature

interface ToastConfig {
  message: string;
  translationVars?: { [key: string]: string | number };
  type?: NotificationType;
  duration?: number;
}

Members

message

property
type:
string

translationVars

property
type:
{ [key: string]: string | number }

type

property

duration

property
type:
number