Skip to content

removeAllFlashMessages(containerName?: string): void

The removeAllFlashMessages method removes all flash messages from the given flash messenger container if it exists.

Input parameters

containerName (optional)

string is a parameter that tells the api which flash-messenger should it refer to. If not specified the messages will be removed from the global flash messenger if any exist inside it.

Event Bus events

This API method dispatches the following events with the Event Bus:

Example

Making a Flash Messages API call to add new flash messages and then remove them from a Flash Messenger webcomponent with the name="my-flash-messenger" attribute if it exists.

    useStorefront(async (storefront) => {
        const flashMessengerApi = storefront.getApiSync('flashMessengerApi');

        flashMessengerApi.addFlashMessages([
            {
                content: `Message 1`,
                type: 'warning',
                isCloseable: true
            },
            {
                content: `Message 2`,
                type: 'success'
            }
        ], 'my-flash-messenger');

        flashMessengerApi.removeAllFlashMessages('my-flash-messenger');
    });
    <flash-messenger name="my-flash-messenger"></flash-messenger>

Example

Making a Flash Messages API call to add new flash messages and then remove them from a global Flash Messenger webcomponent.

    useStorefront(async (storefront) => {
        const flashMessengerApi = storefront.getApiSync('FlashMessengerApi');

        flashMessengerApi.addFlashMessages([
            {
                content: `Message 1`,
                type: 'warning',
                isCloseable: true
            },
            {
                content: `Message 2`,
                type: 'success'
            }
        ]);

        flashMessengerApi.removeAllFlashMessages();
    });

Flash Messenger API methods reference

Webcomponents reference