How To Find Button Click Using Lightning Component
Requirement:
On LC there are two buttons. Both buttons have same function how to get which button have clicked.
Solution
Create a component ButtonClick.cmp
<!--c:ButtonClicked->
<aura:component >
<aura:attribute name="whichButton" type="String" />
<p>You clicked: {!v.whichButton}</p>
<ui:button aura:id="button1" label="Click me" press="{!c.pressMe}"/>
<ui:button aura:id="button2" label="Click me too" press="{!c.pressMe}"/>
</aura:component>
/* ButtonClickedController.js */
({
pressMe: function(cmp, event, helper) {
var whichOne = event.getSource().getLocalId();
console.log(whichOne);
cmp.set("v.whichButton", whichOne);
}
})
Create a app Test.app for Testing
<aura:application extends="force:slds">
<c:ButtonClicked/>
<!-- here c: is org. namespace prefix-->
</aura:application>
On LC there are two buttons. Both buttons have same function how to get which button have clicked.
Solution
Create a component ButtonClick.cmp
<!--c:ButtonClicked->
<aura:component >
<aura:attribute name="whichButton" type="String" />
<p>You clicked: {!v.whichButton}</p>
<ui:button aura:id="button1" label="Click me" press="{!c.pressMe}"/>
<ui:button aura:id="button2" label="Click me too" press="{!c.pressMe}"/>
</aura:component>
/* ButtonClickedController.js */
({
pressMe: function(cmp, event, helper) {
var whichOne = event.getSource().getLocalId();
console.log(whichOne);
cmp.set("v.whichButton", whichOne);
}
})
Create a app Test.app for Testing
<aura:application extends="force:slds">
<c:ButtonClicked/>
<!-- here c: is org. namespace prefix-->
</aura:application>
Comments
Post a Comment