Hi Portia,
If you want to call a server side controller method from lightning component then you have to create action in lightning component.Please refer below code-
Component-DemoComponent
<aura:component controller =”DemoApexCltr”>
<lightning:button variant=”brand” label=”Submit” onclick=”{!c.getAccountJS}” />
</aura:component>
Javascript Controller-
({
getAccountJS : function(component, event, helper) {
var action = component.get(“c.getAllAccount”);
action.setCallback(this,function(response){
console.log(‘:::’+JSON.stringify(response.getReturnValue()));
});
$A.enqueueAction(action);
}
})
Apex Controller – DemoApexCltr
public class DemoApexCltr {
@AuraEnabled
public static list<Account> getAllAccount(){
return [select id,name from account limit 10];
}
}
-
This reply was modified 8 years, 4 months ago by
Ajay Prakash.