Skip to content

Instantly share code, notes, and snippets.

@iamsonal
Created June 27, 2017 13:51
Show Gist options
  • Save iamsonal/495320093ed01b9b63117a2394d79153 to your computer and use it in GitHub Desktop.
Save iamsonal/495320093ed01b9b63117a2394d79153 to your computer and use it in GitHub Desktop.
DynamicComponentController.js
({
createComponent : function(component, event, helper) {
var index = component.get("v.index");
$A.createComponent(
"ui:Button",
{
"label":"Button " + index,
"press":component.getReference("c.show")
},
function(button) {
var body = component.get("v.body");
body.push(button);
console.log(body);
component.set("v.body", body);
}
);
index++;
component.set("v.index", index);
},
removeComponent : function(component, event, helper) {
component.set("v.body", []);
component.set("v.index", 1);
},
show : function(component, event, helper) {
var buttonLabel = event.getSource().get("v.label");
component.set("v.buttonLabel", buttonLabel);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment