Background
I am using a helper function to return data from an apex class. I need to access that data in the component and the controller.
When I return the data in the helper I can console.log it but it does not appear till shortly after the page loads.
In the controller I try and console.log the data and it outputs before the helper is complete. Because of this the output shows null.
Helper
({
loadData: function(component, event, helper) {
var action = component.get("c.loadSalesRepView");
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state == "SUCCESS") {
var dp = JSON.parse(response.getReturnValue());
component.set("v.district_plan", dp);
} else if (response.getState() === "ERROR") {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"type":"error",
"title": "Error!",
"message": "Internal Server Error"
});
toastEvent.fire();
}
});
$A.enqueueAction(action);
}
});
Controller
doInit: function(component, event, helper) {
helper.loadData(component, event, helper);
var data = component.get("v.district_plan");
// This is null
console.log(data);
}
Component Html
<aura:attribute name="district_plan" type="Map" />
<aura:iteration items="{!v.district_plan.goal_themes_md}" var="row" indexVar="index">
option value="{!row.Id}">{!row.description}</option>
</aura:iteration>
Question
How do I access the values from the helper in the html and the controller?