0

Error

This page has an error. You might just need to refresh it. Action failed: c:LC_1103_Eg4_SumUpEven$controller$calc [ation is not defined] Failing descriptor: {c:LC_1103_Eg4_SumUpEven$controller$calc}

Class

public class LC_1103_Eg4_SumUpEven {
    @AuraEnabled
    public static Integer sumuptoeven(integer numb)
    {
      integer Res=1;
      integer count=0;
        while(count<numb){
            Res=Res+count;
            count=count+2;
        }
        Return Res;
    }

}

component

<aura:component controller="LC_1103_Eg4_SumUpEven">
    <aura:attribute name="num" type="Integer"/>
    <aura:attribute name="Result" type="Integer"/>
    
    <lightning:card title="SUM">
        <lightning:input label="Enter the Number" value="{!v.num}"/>
        <lightning:button label="Calulate" onclick="{!c.calc}"/><br/>
        <lightning:input label="Result" value="{!v.Result}"/>
         
    </lightning:card>
    
</aura:component>

controller

({
    calc : function(component, event, helper) {
        var n=component.get("v.num");
         var action=component.get("c.sumuptoeven");
        action.setParams({"numb":n});
        ation.setCallback(this,function(response){
              var state=response.getState();
                if(state=='SUCCESS')
                {
                    var res=response.getReturnValue();
                    component.set("v.result",res);
                }                  
          });
        $A.enqueueAction(action);
    }
})

Application

<aura:application extends="force:slds">
    <c:LC_1103_Eg4_SumUpEven/>
</aura:application>
1
  • Please use the format tool { } to properly format the code and add details about the problem you are facing. Mar 11, 2021 at 14:46

1 Answer 1

1

You have a very small problem, you have misspelled the action variable. Please check the below code.

({
    calc : function(component, event, helper) {
        var n=component.get("v.num");
         var action=component.get("c.sumuptoeven");
        action.setParams({"numb":n});
        action.setCallback(this,function(response){
              var state=response.getState();
                if(state=='SUCCESS')
                {
                    var res=response.getReturnValue();
                    component.set("v.result",res);
                }                  
          });
        $A.enqueueAction(action);
    }
})
3
  • Tq..Rahul. The Error gone now.
    – user90016
    Mar 11, 2021 at 15:29
  • But The problem is Result is not getting displayed on the output paga
    – user90016
    Mar 11, 2021 at 15:29
  • 1
    @Mahi JavaScript is cAsE-sEnSiTiVe. You named the attribute Result, but assigned to attribute result.
    – sfdcfox
    Mar 11, 2021 at 15:32

You must log in to answer this question.