Display a simple Alert using Aura Component #inSalesforce

 Display a simple Alert using Aura Component


A modal that communicates a state affecting the entire system, not just a feature or page. This component requires API version 54.0 and later.


lightning:alert


component:

<aura:component>
    <aura:import library="lightning:alert" property="LightningAlert" />
    <lightning:button onclick="{! c.openAlert }" label="Open Alert"/>
</aura:component>


controller:

({
    openAlert: function(cmp, event, helper) {
        helper.openAlert(cmp, event);
    }
});


helper:

({
    openAlert: function(cmp, event) {
        this.LightningAlert.open({
            message: 'this is the alert message',
            theme: 'error',
            label: 'Error!',
        }).then(function() {
            console.log('alert is closed');
        });
    }
});



Visual: https://www.youtube.com/watch?v=jUfnzxWPLec

Comments