3

I wish to make dynamic aura:id's and for that i want to use $A.createComponent, now i already have a component called 'pageComponentCard' that i wish to call but i can't do this.

The code in question:

    $A.createComponent(
        "c:pageComponentCard",
        {
            "component":"{!v.cardId}",
        },
        function(newCard, status, errorMessage){
            if (status === "SUCCESS") {
                var body = cmp.get("v.body");
                body.push(newCard);
                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);
            }
        }
    );

Both tried with and without the "c:"

1 Answer 1

3

The mistake is at passing attribute value to pageComponentCard "component":"{!v.cardId}", {!v.cardId} it is used in component markup . you must use component.get("v.cardId") to get attribute value.in controller.

$A.createComponent(
        "c:pageComponentCard",
        {
            "component":component.get("v.cardId"),
        },
        function(newCard, status, errorMessage){
            if (status === "SUCCESS") {
                var body = cmp.get("v.body");
                body.push(newCard);
                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);
            }
        }
    );
2
  • Thanks for your comment! The console does generate the following: " Error: Unknown component 'markup://nvmsconfigtool:pageComponentCard'. ", any idea?
    – Olsthoorn
    Commented Apr 10, 2017 at 9:09
  • please post a component markup code c:pageComponentCard component.and you cant use attribute name as component it may cause error.
    – vignesh
    Commented Apr 10, 2017 at 9:13

You must log in to answer this question.

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