addFlashMessages(flashMessageOptions: TFlashMessageOptions[], containerName?: string): string[]¶
The addFlashMessages
method adds multiple flash messages to the page. It requires an existing flash-messenger webcomponent to be present on the page.
Input parameters¶
flashMessages¶
flashMessages
is a mandatory parameter of the TFlashMessageOptions array type.
containerName (optional)¶
string
is a mandatory parameter that tell the api which flash-messenger should it refer to. If not specified the messages will be added to the global flash messenger.
Returned value¶
addFlashMessages
return value is of type string[]
and contains IDs of all of the added flash messages.
Event Bus events¶
This API method dispatches the following events with the Event Bus:
- FlashMessengerApi.addFlashMessages - when displaying flash messages
Example¶
Making a Flash Messages API call to add a flash message to a Flash Messenger webcomponent with the name="my-flash-messenger"
attribute if it exists.
Example¶
Making a Flash Messages API call to add a flash message to 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'
}
]);
});