Skip to main content
Handler3.cmp:

------------------

<aura:component >

    <aura:attribute name="aval" type="Integer"/>

    <aura:attribute name="bval" type="Integer"/>

    <aura:attribute name="cval" type="Integer"/>

    <aura:handler name="init" value="{!this}" action="{!c.test}"/>

    <lightning:card title="Calculation">

        A value:{!v.aval}<br/>

        B value:{!v.bval}<br/>

        C value:{!v.cval}

    </lightning:card>

</aura:component>

Handler3Controller.js

----------------------------

({

    test: function(component, event, helper) {

        var a=component.get("v.aval");

        var b=component.get("v.bval");

        var cval=a+b;

        componet.set("v.cval",cval);

        

        

    }

})

Handler3_App.app

-------------------------

<aura:application extends ="force:slds">

    <c:Handler3 aval="10" bval="20" />

</aura:application>
2 respostas
  1. 1 de jun. de 2021, 15:10

    Hi Anji,

    Please find the solution.

    test: function(c,e,h){

    var a=c.get("v.aval");

    var b=c.get("v.bval");

    var cval=a+b;

    console.log("outside if:::"+cval);

    if(cval){

    console.log("Inside if:::"+cval);

    c.set("v.cval",cval);

    }

    }

    Actually, In your code, there is no data inside this variable "cval" so how you can set if there is no data.

    c.set("v.cval",cval);

    I have correct your code if there is no data then it will not enter inside the if statement.

    Please let me know it is working or not.

    Please mark it as the Best Answer if it helps you.

    Thank You
0/9000