Last active
January 16, 2021 10:18
-
-
Save pozil/4a3fedf30836379dd6fc7c8668046f18 to your computer and use it in GitHub Desktop.
Lightning - Displaying a system toast with a few lines of code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global"> | |
<div class="slds-m-around--xx-large slds-text-align--center"> | |
<lightning:button label="Fire toast event" onclick="{! c.fireToastEvent }"/> | |
</div> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
fireToastEvent : function(component, event, helper) { | |
var toastEvent = $A.get("e.force:showToast"); | |
toastEvent.setParams({ | |
"title": "Success!", | |
"message": "It works!", | |
"type": "success" | |
}); | |
toastEvent.fire(); | |
} | |
}) |
Hi @Alimali-Stephen, I'm not sure about what you mean by an existing component. Is that a custom component that you can edit?
If not, you won't be able to plug this code sample into it.
Yes it's a component that you can edit. I just need to add a method on the code that will show notification to users on click of a button.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to display a toast at an existing component. A notification should show on click of a certain button, how do I go about that?