Is it possible to dynamically create a lightning component and put it into a custom lightning component?
For example, I have the following custom lightning component:
<aura:component>
<div class="wasCreatedDynamicallyInCode">
Here should go the component:
<div id="addALightningComponentHere">
</div>
</div>
</aura:component>
And I have a component which statically I would add in the following way:
<aura:component>
<div class="wasCreatedDynamicallyInCode">
Here should go the component:
<div id="addALightningComponentHere">
<namespace:MyComponent myArg="{!v.myArg}"/>
</div>
</div>
</aura:component>
How could I add the line <namespace:MyComponent myArg="{!v.myArg}"/>
dynamically from client-side controller?
I am aware of everything written here. It does not help me to solve the problem, so I am posting it here.
UPDATE
In order to show why addition of {!body}
confuses me I will tweak the code a little bit.
<aura:component>
<div class="wasCreatedDynamicallyInCode">
Here should go the first component:
<div id="addALightningComponentHere1">
<namespace:MyComponent myArg="{!v.myArg}"/>
</div>
</div>
<div class="wasCreatedDynamicallyInCode">
Here should go the second component:
<div id="addALightningComponentHere2">
<namespace:MyComponent myArg="{!v.myArg}"/>
</div>
</div>
</aura:component>
Not only the component I am setting in place of {!v.body}
, but also the {!v.body}
and aura:id
for encompassing element should be generated at runtime.
{!v.body}
.{!v.body}
?Aura.Component[]
), beyond justv.body
.