olifreeman of oegen Developers
10/5/2018 - 2:36 PM

Dynamically Create Multiple Components

$A.createComponents([
    ["c:ComponentName", {
      "componentAttribute" : "attributeValueToSet"
    }],
    ["c:ComponentName", {
      "componentAttribute" : "attributeValueToSet"
    }]
  ],
  function(components, status, errorMessage){
    if(status === "SUCCESS"){
      var firstCmp = components[0];
      var secondCmp = components[1];
      //Here, you can nest components inside each other
      //By doing stuff like
      //firstCmp.set("v.body", secondCmp);
    }
    else if(status === "INCOMPLETE"){
      console.log('No response from server or client is offline.');
    }
    else if(status === "ERROR"){
      console.log("Error: " + errorMessage);
    }
  }
  );