Play Games

Search This Blog

Tuesday, May 17, 2022

Show alerts in Lightning Web Component(LWC) - SalesforceGlobe4U

Solution: Use LightningAlert module to show alert in lightning web component.

showAlertInLWC.html

<template>

    <lightning-card>

        <lightning-button label="Show Alert" onclick={showAlert}></lightning-button>

    </lightning-card>

</template>

showAlertInLWC.js

import { LightningElement } from 'lwc';

import LightningAlert from 'lightning/alert';

export default class ShowAlertInLWC extends LightningElement {

    async showAlert() {

        await LightningAlert.open({

            message:'Welcome to Lightning Alert in LWC',

            theme:'success',

            label:'This is a alert Component'

        });

    }

}

showAlertInLWC.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

    <apiVersion>54.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:




No comments:

Post a Comment