3

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>
  • 2
    Creating Dynamic component in controller helped in Passing parameters once attribute value is available in parent init. Thanks. – Sriram Dec 6 '16 at 3:37
  • you may want to put that as an answer with code to help community – Mohith Shrivastava Dec 6 '16 at 4:45
7

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>
  • This is a better solution! – Raul Dec 6 '17 at 10:25
-1

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);
            }
        });
  • 3
    It looks like a hack - is there any other (proper) way to render child component after all required data is loaded? – Yury Bondarau Feb 27 '17 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.

  • That would be sort anti-pattern – Raul Dec 6 '17 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.