7 answers
Hi WonJeung,Change your onClick - > onclick. In your case the controller method was not fire.Please try below code it works fine for me and let me know if this works for you. If still need modifications do let me know. Component :
Controller :<aura:component >
<aura:attribute name = 'num1' type = 'Integer' default = '15'></aura:attribute>
<aura:attribute name = 'num2' type = 'Integer' default = '20'></aura:attribute>
<aura:attribute name = 'sum' type = 'Integer'></aura:attribute>
<div>
<p>Add</p><lightning:button label = 'Add' onclick = '{!c.addMethod}'/>
<p>{!v.num1} + {!v.num2} = {!v.sum}</p>
</div>
</aura:component>
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.Thanks,Ajay Dubedi({
addMethod : function(component, event, helper) {
//Add numbers
var num1 = component.get("v.num1");
var num2 = component.get("v.num2");
console.log(num1);
console.log(num2);
var sumResult = num1 + num2;
component.set('v.sum', sumResult);
}
})