Apex Class:
public class SampleAuraController { //Properties @AuraEnabled public String FirstName {get;set;} @AuraEnabled public String LastName {get;set;} @AuraEnabled public static SampleAuraController getData() { SampleAuraController obj = new SampleAuraController(); obj.FirstName = 'Biswajeet'; obj.LastName = 'Samal'; return obj; } }
Lightning Component:
<!--Sample.cmp--> <aura:component controller="SampleAuraController" implements="flexipage:availableForAllPageTypes,force:appHostable"> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <aura:attribute name="obj" type="SampleAuraController"/> <!--Component Start--> <div class="slds-m-around_xx-large"> <strong>First Name : {!v.obj.FirstName}</strong> <br/> <strong>Last Name : {!v.obj.LastName}</strong> </div> <!--Component End--> </aura:component>
Lightning Component JS Controller:
({ doInit : function(component, event, helper) { var action = component.get('c.getData'); action.setCallback(this,function(response){ var state = response.getState(); if (state === "SUCCESS") { var result = response.getReturnValue(); component.set('v.obj', result); } }); $A.enqueueAction(action); } })