Play Games

Search This Blog

Monday, November 1, 2021

If condition in lightning web component - Salesforce Globe For You

If condition in lwc component - Salesforce Globe For You

Solution: <template if:true={condition}> </template> 

Example:

ifConditionLWC.html

<template>

    <lightning-card title="If condition LWC Component">

        <div class="slds-m-around_medium">

            <template if:true={bTrue}>

                <div class="slds-m-vertical_medium">

                    This Will display only when boolean variable bTrue is true.

                </div>

            </template>

        </div>

    </lightning-card>

</template>

ifConditionLWC.js

import { LightningElement,track } from 'lwc';

export default class IfConditionLWC extends LightningElement {

    @track bTrue = true;

}

ifConditionLWC.js-meta.xml

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

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

    <apiVersion>48.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