1

Why does <ui:button> work but <lightning:button> does not work?

Component:

<aura:component>
    <ltng:require 
        styles="{!$Resource.SLDS212 + '/assets/styles/lightning-design-system-ltng.css'}"
        scripts="{!$Resource.jsLibraries + '/jsLibOne.js'}"
        afterScriptsLoaded="{!c.scriptsLoaded}" />
    <ui:button label="myButton" press="{!c.doSomething}"/>
    <lightning:button name="myButton" onclick="{!c.doSome}"/>
</aura:component>

Controller:

({
    doSomething: function(cmp, event, helper) {
        var button = event.getSource().get("v.label");
        alert(button);

    },
    doSome: function(cmp, event, helper) {
        var button = event.getSource().get("v.name");
        alert(button);

    }
})
2

The name attribute is optional, use label

<lightning:button label="Submit" onclick="{! c.doSome }" />

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_button.htm

You may get an error on getSource() if you are on winter box, there seems to be a fix in Spring 17:

Lockerservice and event.getSource()

Winter 17 release : event.getSource is not a function on lightning:button

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.