Friday 24 July 2020

Migrate Expressions (Aura to LWC)

Hi,

Here we are going to learn how we can migrate expressions from markup in the Aura component to JavaScript in a Lightning web component.

In the Lightning web component, we can't use expressions in markup (template) but we can use expressions in the Aura component's markup. 

If we have to use expressions in Lightning web components then we have to write this expression in LWC JavaScript File and return the result with the help of getter methods as shown below.

Aura:
Syntax:
<aura:if isTrue="{! (!v.isShow? true : false) }">
    <div>Conditional Code</div>
</aura:if>


LWC:

Syntax:

<template>
    <div if:true={showValues}>Conditional Code</div>
</template>
import { LightningElement } from 'lwc';
export default class MyComponentName {
    get showValues() {
        return isShow? true : false;
    }
}


Reference:


2 comments:

  1. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles Bulk Metadata Operations

    ReplyDelete
  2. Thank you much for sharing this wonderful post.
    AWS Training in Chennai

    ReplyDelete

How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...