EP-03 | Conditionally Render Elements in LWC | LWC Stack ☁️⚡️


  LWC Stack is Lightning Web Component tutorial series by Salesforce MVP Kapil Batra. In this series you will find LWC tutorials from beginner to intermediate level.

So if you are working on it or planning to learn LWC then this video series is for you. Let's learn and grow together ! Please check complete code below from LWC Stack EP-03

HTML
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<template>
    <lightning-card title="Conditional Rendering Elements" icon-name="utility:user">
        <div class="slds-var-m-around_medium">
            Hello, {myValue}!
        </div>
        <div style="padding:10px">
       <lightning-input type="checkbox" label="Click me" onchange={handleChange}>
           </lightning-input>
           <template if:true={showMe}>
               I am Visible
           </template>
           <template if:false={showMe}>
               I am not Visible.
           </template>
    </div>
    </lightning-card>
</template>

JavaScript
1
2
3
4
5
6
7
8
9
import { LightningElement } from 'lwc';

export default class ConditionallyRenderElements extends LightningElement {
    myValue="Salesforce Bolt";
    showMe = false;
    handleChange(event){
        this.showMe = event.target.checked;
    }
}
Output


Checkout complete tutorial below

 If you have any question please leave a comment below.

If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks
Happy Coding :)

Post a Comment

0 Comments