Dynamically creating components using $A.createComponent()

Components can be dynamically injected by using the $A.createComponent() function. The syntax for this function is as follows:

$A.createComponent(String type, Object attributes, function callback)

The parameters used in the $A.createComponents function are described as follows:

  • type: The type of component to create; for example, ui:button.
  • attributes: A map of attributes for the component, including the local ID (aura:id).
  • callback(cmp, status, errorMessage): The callback to invoke after the component is created. The callback has three parameters:
  • cmp: The component that was created. This enables you to do something with the new component, such as add it to the body of the component ...

Get Learning Salesforce Lightning Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.