0

I have a below lightning component:

<!--ParentCmp--->
<aura:component>

...

<aura:if isTrue="{!!v.condition}">
    <c:childCmp/>
</aura:if>

...

</aura:component>

When this above component gets loaded, the init method of child component childCmp gets called even if the condition isTrue="{!!v.condition}" is false.

I do not want to load the init of childCmp which is why I kept it in False condition but still the init method of child component childCmp is getting invoked, what should I do to stop the loading of childCmp Init when parent component loads?

1 Answer 1

0

Set the condition such that the ifTrue property evaluates to false on initial rendering.

<aura:attribute name="condition" default="true" type="Boolean" />

...

<aura:if isTrue="{!!v.condition}">

Note that {!!v.condition} means "when condition is false", because you have an extra ! in there. I made no assumption about if you meant to do this, just be aware that ! in an expression is the not operator.

Also, just be aware that "False" is a truthy value, while false (no quotes, lowercase) is a proper falsy value. Make sure you're not accidentally setting a truthy value.

2
  • I did set the value to false on the initial load but still the init of child is getting invoked.
    – sfdc07
    Commented Feb 24, 2022 at 14:36
  • @sfdc07 I tested this, and it did work as expected. There's something wrong with your code if the initializer is being called. Copy-paste this code in to an org. Change false to true to see the initialization happen.
    – sfdcfox
    Commented Feb 24, 2022 at 15:54

You must log in to answer this question.

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