• Stephane Paquet 9
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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.