5

I am new to Salesforce lightning, just started using aura tags.

I have to pass parameters to a component (Aura Table) inside parent component (no inheritance), Unfortunately child component's init is being executed before Parent's. Attribute 'query' is considered as undefined in child as the value was assigned later in parent's init.

Is there anyway I can make child component's init wait before parent init completes its part?

Also I tried creating Dynamic component in controller and adding to v.body, Lost the Table style, No headers. Am I missing some thing. Let me know if there is any other approach.

Parent Component

<aura:component controller="xyz" implements="force:appHostable">
  <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
  <aura:attribute name="query" type="String"/>
 <div>
     <c:childComponent queryParam="{!v.query}" />
 </div>
</aura:component>
0

3 Answers 3

10

In Component initialization child component Init event is fired before parent Init event.Use<aura:if> tag to check all required attributes before creating component.

<aura:component controller="xyz" implements="force:appHostable">
  <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
  <aura:attribute name="query" type="String"/>

  <aura:if isTrue="{!v.query}">
    <c:childComponent queryParam="{!v.query}" />
  </aura:if>
</aura:component>
0
-2

Creating Dynamic component in parent component's controller helped in Passing parameters once attribute value is available in parent init.

$A.createComponent("c:ChildComponent", { 
        "Param1": val1, 
        "Param2": val2
        }, function(newCmp) {
            if (component.isValid()) {
                component.set("v.body", newCmp);
            }
        });
1
  • 3
    It looks like a hack - is there any other (proper) way to render child component after all required data is loaded? Feb 27, 2017 at 9:34
-2

Use the change event in the child component then you will get the attribute's value in the action method that you call on change.

1
  • That would be sort anti-pattern
    – Raul
    Dec 6, 2017 at 10:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .