1

Is it possible to set lightning component aura:id attribute dynamically while creating the component?

Here is my code for the component creation:

  $A.createComponent(
                "c:RPGFlowComponent",
                {
                    flow: {
                        Id: flowId
                    }
                },
                helper.setUpperRightComponent(component)
            );



setUpperRightComponent: function(component) {
        return function(newComponent, status, errorMessage) {
            if (status === "SUCCESS") {
                const rightLowerPart = component.find("rightUpperComponent");
                const body = [];
                body.push(newComponent);
                rightLowerPart.set("v.body", body);
            }
            else if (status === "INCOMPLETE") {
                console.log("INCOMPLETE")
            }
            else if (status === "ERROR") {
                console.log("ERROR: " + errorMessage);
            }
        }
    }

How could I modify it to set the aura:id attribute on it?

1 Answer 1

3

You can specify aura:id in the createComponent call:

$A.createComponent(
    "c:RPGFlowComponent",
    {
        "aura:id": "somevalue", // You can set whatever you like here
        flow: {
            Id: flowId
        }
    },
    helper.setUpperRightComponent(component)
);

In theory, you could probably set aura:id in the callback, but I wouldn't depend on that working, as it might break things.

You must log in to answer this question.

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