You need to sign in to do that
Don't have an account?
Israel Jimenez
How can I use a ToastEvent in LightningModal LWC?
Hi everybody!!
When I use the
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
on
...extends LightningModal {}
Show me a error:
[Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.]
Help me, please!
Thanks!!
When I use the
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
on
...extends LightningModal {}
Show me a error:
[Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.]
Help me, please!
Thanks!!
It should be like below format.
Check below reference for same.
https://www.sfdcpoint.com/salesforce/lightning-web-component-lwc-toast-messages/
https://www.biswajeetsamal.com/blog/lightning-web-componentlwc-toast-messages/
Please mark as Best Answer if above information was helpful.
Thanks,
To trigger a toast from a Lightning web component, in the component’s JavaScript class, import ShowToastEventfrom lightning/platformShowToastEvent.
I have mentioned the format:
import { LightningElement } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent'; //Importing ToastEvent
export default class MyComponent extends LightningElement {
handleButtonClick() {
const event = new ShowToastEvent({
title: 'Success',
message: 'The operation was successful.',
variant: 'success',
});
this.dispatchEvent(event);
}
}
For more information and detailed documentation, you can also refer to the: SFDC Point (https://www.sfdcpoint.com/salesforce/lightning-web-component-lwc-toast-messages/" target="_blank) and Salesforce Document (https://developer.salesforce.com/docs/component-library/bundle/lightning-platform-show-toast-event/documentation" target="_blank)