I am trying to access the attribute which I am assigning the value in Helper, and calling the helper in Controller init, but while accessing the the same attribute in init, its returning undefined.
Here is my code
Helper
userName : function(component) {
//loading user related data
var action = component.get("c.getUserName");
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.Name", response.getReturnValue());
// alert('$$$' + component.get("v.Name"));
}
});
$A.enqueueAction(action);
},
Controller
doinit : function(component, event, helper) {
helper.userName(component);
//here its returning undefined
alert(component.get("v.Name"));
}
Component
<aura:handler name="init" value="{!this}" action="{!c.doinit}"/>
<aura:attribute name="Name" type="String" />
Asynchronous Ajax Request
.