About

Edit photo

Sunday, August 27, 2017

Lightning example, Addition of two numbers in lightning using helper


Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="fname" type="Integer"/>
    <aura:attribute name="lname" type="Integer"/>
    <aura:attribute name="fullname" type="Integer"/>
    
    First name: <ui:inputText value="{!v.fname}"/>
    <br/>
    Last name: <ui:inputText value="{!v.lname}"/>
    <br/>
    <ui:button label="click me to get full name" press="{!c.fullname}" />
    <br/>
    Full name is: {!v.fullname}
</aura:component>


App:
<aura:application >
    <c:basics1/>
</aura:application>


Controller:
({
 fullname : function(component, event, helper) {
  helper.addHelper(component)
 }
})


Helper:
({
 addHelper : function(component, event, helper) {
  console.log("you pressed me buddy!");
        var first = component.get("v.fname");
        var last = component.get("v.lname");
        console.log(first);
        
        var fullname = parseInt(last) + parseInt(first);
        console.log(fullname);
        
        component.set("v.fullname",fullname);
 }
})


Output:

Lightning example, Get FullName



Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="fname" type="string"/>
    <aura:attribute name="lname" type="string"/>
    <aura:attribute name="fullname" type="string"/>
    
    First name: <ui:inputText value="{!v.fname}"/>
    <br/>
    Last name: <ui:inputText value="{!v.lname}"/>
    <br/>
    <ui:button label="click me to get full name" press="{!c.fullname}" />
    <br/>
    Full name is: {!v.fullname}
</aura:component>

App:
<aura:application >
    <c:basics1/>
</aura:application>

Controller:
({
 fullname : function(component, event, helper) {
  console.log("you pressed me buddy!");
        var first = component.get("v.fname");
        var last = component.get("v.lname");
        console.log(first);
        
        var fullname = last + ', '+first;
        console.log(fullname);
        
        component.set("v.fullname",fullname);
 }
})

Output:

@SsaiK