You need to sign in to do that
Don't have an account?
Trailhead Aura $A.createComponents in javascript doesn't see to work
I am attempting to use the examples on Trailhead Lightning component "Using JavaScript Controllers with Components" and when I use the examples that use the $A.createComponents none of the JS work.
I created a component createComponent.cmp with the following code:
<!--docsample:createComponent-->
<aura:component>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<p>Dynamically created button</p>
{!v.body}
</aura:component>
and a controller createComponentController.js with the following code:
/*createComponentController.js*/
({
doInit : function(cmp) {
$A.createComponent(
"ui:button",
{
"aura:Id": "findableAuraId",
"label": "Press Me",
"press": cmp.getReference("c.handlePress")
},
function(newButton){
//Add the new button to the body array
if (cmp.isValid()) {
var body = cmp.get("v.body");
body.push(newButton);
cmp.set("v.body", body);
}
}
);
},
handlePress : function(cmp) {
console.log("button pressed");
}
})
This is right out of the book. The message "Dynamically created button" shows on the screen, but there are no buttons.
I created a component createComponent.cmp with the following code:
<!--docsample:createComponent-->
<aura:component>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<p>Dynamically created button</p>
{!v.body}
</aura:component>
and a controller createComponentController.js with the following code:
/*createComponentController.js*/
({
doInit : function(cmp) {
$A.createComponent(
"ui:button",
{
"aura:Id": "findableAuraId",
"label": "Press Me",
"press": cmp.getReference("c.handlePress")
},
function(newButton){
//Add the new button to the body array
if (cmp.isValid()) {
var body = cmp.get("v.body");
body.push(newButton);
cmp.set("v.body", body);
}
}
);
},
handlePress : function(cmp) {
console.log("button pressed");
}
})
This is right out of the book. The message "Dynamically created button" shows on the screen, but there are no buttons.

What is the name of your app? if it is TestApp.app just take the same code but put it in another app like "ThisApp.app" and it should work ;)