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:
0 comments:
Post a Comment