2

I am trying to create and add components dynamically to application. The new component is created successfully but not rendering in UI.

Please find the source code below. I am passing component name via URL param to the application

Application

<aura:application >
    <aura:attribute name="componentName" type="String" default=""/>

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:application>

App Controller

doInit : function(component, event, helper) {
        var compName = "c:" + component.get("v.componentName");
        $A.createComponent(
            compName,
            {},
            function(newComp, status){
                if (component.isValid()) {
                    var body = component.get("v.body");
                    body.push(newComp);
                    component.set("v.body", body);
                }
            });
    }
3

You need to include {!v.body} in the component mark up, where you you want to display your dynamic component. for example :

<aura:application >
    <aura:attribute name="componentName" type="String" default=""/>
    The dynamic component oes here :
    {!v.body}
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:application>

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.