Going straight to the point, i have spent quite some time yesterday figuring out createComponent and now it finally works, but the main reason i wish to use $A.createComponent instead of a iteration is because i found out that you can use a dynamic aura:id with $A.createComponent.

Code snippet from the helper:

$A.createComponent("nvmsconfigtool:pageComponentCard", {
            "aura:id": "cardId",
            "component": results[i],
            "class": "slds-size--1-of-1 slds-medium-size--1-of-2 slds-large-size--1-of-3 slds-p-around--small",
            function(comp, status, errorMessage) {
                if (status === "SUCCESS") {
                    var body = cmp.get("v.body");
                    cmp.set("v.body", body);
                } else if (status === "INCOMPLETE") {
                    console.log("No response from server or client is offline.")

                } else if (status === "ERROR") {
                    console.log("Error: " + errorMessage);

If my research is correct, this code should be working just fine and it does! Its just that it doesn't seem to make the Aura:id, i tried to find it using cmp.find("cardId")


I think you tried component.find("cardId") and you were not able to get any component. And maybe that is why you are assuming it does not make the aura:id.

Well, here are a couple of things that i figured when working with the same.

  • The aura:id is not visible on the dynamic components, as it mostly renders the component markup:// that we have defined in the components.
  • However, the aura:id is present in the context of aura framework. So you should be able to use aura:id to fetch the component itself.

The reason why you are not able to find the component is because of the following

var body = cmp.get("v.body");
cmp.set("v.body", body);

The component markup is wrapped inside the v.body, hence try something like follows to get the component.

var body = component.get("v.body) // now this will contain the dynamic component
body[0].find("cardid").destroy() // Body may be an array .. here is a sample usage. 

Hope it helps .

| improve this answer | |
  • 1
    And as usual i got "d'ohh! I should have known that", thanks a bunch! It seems to find the aura:id's now and my code is back on track – Olsthoorn Apr 11 '17 at 7:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.