Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

createComponent()

Create a component from a type and a set of attributes. This method accepts the name of a type of component, a map of attributes, and a callback to notify the caller.

Signature

createComponent(String type, Object attributes, function callback)

Parameters

type
Type: String
The type of component to create. For example, "lightning:button".
attributes
Type: Object
A map of attributes to send to the component. These attributes take the same form as in the markup, including events {"press":component.getReference("c.handlePress")}, and id {"aura:id":"myComponentId"}.
callback(cmp, status, errorMessage)
Type: function
The callback to invoke after the component is created. The callback has three parameters.
  1. cmp—The component that was created. This parameter enables you to do something with the new component, such as add it to the body of the component that creates it. If there’s an error, cmp is null.
  2. status—The status of the call. The possible values are SUCCESS, INCOMPLETE, or ERROR. Always check that the status is SUCCESS before you try to use the component.
  3. errorMessage—The error message if the status is ERROR.