When I load this Lightning component a child component's init
gets a null pointer as an attribute doesn't yet exist. I is populated via an Apex action during the parent components init
. I know that a Child components init is called before the parents init. Nonetheless I need to make this work without dynamic components. And I'd expect this to be a very common scenario.
Can this be solved by events or change handlers or refresh view calls??
Markup
<aura:component controller="MyCtrl" implements="force:lightningQuickAction,force:hasRecordId">
<aura:attribute name="attributes" type="List" access="private" />
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<c:attributeList items="{!v.attributes}" />
</aura:component>
Controller
({
init: function(cmp, evt, helper) {
var action = cmp.get("c.queryAttributes");
action.setCallback(this, function(response) {
cmp.set("v.attributes", response.getReturnValue());
});
$A.enqueueAction(action);
},
});
init
handler on the child component, I use an handler on the attribute value change like this:<aura:handler name="change" value="{!v.items}" action="{!c.doInit}"/>