I would like to dynamically create components from other component. The thing is that, if any of those child components use events, I'd like to create the needed aura:attributes to store the info.

Anyone know if I can create it with $A.createComponent ? Any example?

Thanks in advance!


<aura:component >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <!-- BODY -->
    <div aura:id="modal" role="dialog" tabindex="-1" class="slds-modal slds-fade-in-open">
        <div class="slds-modal__container">
</aura:component >


doInit : function(component){
    var attributes = { "name" : 'msg',
                      "type" : 'String',
                      "default" : 'Holaaa'};

                       function(newCmp, status, errorMessage){
                           console.log("Status : " , status)
                           console.log("newCmp: ", newCmp)
                           if (status === "SUCCESS") 
                              component.set("v.customParams", newCmp)

In the browser console, it shows:

Status = ERROR

newCmp: null


An internal server error has occurred. Error ID: 1834334539-240 (-488974888)

  • 1
    You're trying to set attributes on the component as it's created? Maybe you could show some code that demonstrates what you've tried so far? Even if it's not correct, seeing code might help us solve your question better. – sfdcfox Feb 25 '18 at 20:51
  • @sfdcfox now you can see the code – user3529582 Feb 25 '18 at 21:12
  • 1
    Nope, you can't define attributes this way. Whatever problem you're trying to solve, you'll need to do it using already-defined attributes. This is almost certainly an x-y problem; ask about your original problem so we can help you. – sfdcfox Feb 25 '18 at 21:40

Surely the only reason for attributes is to allow the framework to render them? In which case you'll need to specifically add them in anyway to the .cmp.

If you're just using them to store and manipulate in the controller javascript, you can just have one, specified attribute that is of type Object, and takes a Javascript object of any shape you're trying to pass into it.

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.