-2

Apex code-

public class Controller_Apex {
    @AuraEnabled
    Public static string callApexmtd(){
        return 'Amit kumar';
    }

}

component

<aura:component >
    <aura:attribute name="Result" type="string" />
    <lightning:button label="submit" onclick="{!c.show}" />

</aura:component>

controller:

({
    show : function(component, event, helper) {
        var abc=component.get("c.callApexmtd");
        abc.setcallback(this,function(response)
        {
        var state=response.getstate();
        console.log('state :' +state);
        if(state==='success'){
            var result=response.getreturnvalue();
            console.log('result' +result);
            component.set("v.result",result);
        }
        });
    $A.enqueueAction(abc);
}
})

Application:

<aura:application extends="force.slds" >
    <c:component_apex />

</aura:application>

getting this error:

This page has an error. You might just need to refresh it. Unable to find action 'callApexmtd' on the controller of Capita_one:component_apex Failing descriptor: {Capita_one:component_apex}

4

Your <aura:component> does not declare a controller attribute. You must explicitly declare which Apex class is serving as controller for this component so that the runtime can create controller instances and reference the appropriate methods.

Not the answer you're looking for? Browse other questions tagged or ask your own question.