Ember CLI Flash Messages

7.0.0 · active · verified Wed Apr 22

ember-cli-flash is a robust Ember addon that provides a simple yet highly configurable solution for displaying flash messages (e.g., growl, toast notifications) within Ember applications. It includes both a `flashMessages` service for managing messages and a `FlashMessage` component for rendering them. Currently in stable version 7.0.0, the library generally follows a yearly major release cycle, with minor and patch updates in between, aligning with Ember's LTS and general release schedule. Key differentiators include its promise-aware API, out-of-the-box styling support for frameworks like Bootstrap and Foundation, and comprehensive TypeScript definitions allowing for custom message fields with generics, making it type-safe and adaptable to complex notification requirements. It integrates well with modern Ember tooling, requiring Ember.js v4.12 or above and Embroider or ember-auto-import v2.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates injecting the `flashMessages` service into an Ember Glimmer component and using its convenience methods (`.success`, `.danger`) to display messages with custom options, including promise-based handling and clearing all messages.

import Component from '@glimmer/component';
import { service } from '@ember/service';
import { action } from '@ember/object'; // Or @glimmer/tracking for reactivity if needed

import type { FlashMessagesService } from 'ember-cli-flash';

export default class MyComponent extends Component {
  @service declare flashMessages: FlashMessagesService;

  @action
  showSuccessMessage() {
    this.flashMessages.success('Data saved successfully!', {
      timeout: 3000,
      sticky: false,
      type: 'success', // For Bootstrap/Foundation styling
      // Custom options are also supported
      user: 'currentUser',
      priority: 100
    });
  }

  @action
  showErrorMessage() {
    this.flashMessages.danger('Failed to save data. Please try again.', {
      timeout: 5000,
      sticky: true,
      showProgress: true
    }).then(flashObject => {
      console.log('Flash message dismissed or timed out:', flashObject.message);
    });
  }

  @action
  clearAllMessages() {
    this.flashMessages.clearMessages();
  }
}

// In your application template (e.g., application.hbs), typically:
// <FlashMessage::Component />
// Ensure your app's CSS includes styles for .alert, .alert-success, etc.

view raw JSON →