2

I'm building a generic button lightning component, and I don't find how to implement a parameter which will trigger a controller JS function on the component including the button ( exactly like the press parameter of ui:button )

Sample:

CmpButton.cmp
    <aura:attribute name="press" type="????">
    <ui:button press="???" />

SomeComponent.cmp
    <c:CmpButton press="{c.someComponentMethod}" />

SomeComponent.js
    someComponentMethod: function(component,event,helper){
       // action on SomeComponent
}

I would like SomeComponent.someComponentMethod to be called when my included button is pressed

Many thanks & best regards

1 Answer 1

4

You need to make the attribute of type AuraAction. This will enable you to pass in the handler action directly.

Define it like this:

<aura:attribute name="press" type="Aura.Action" default="{!c.someAction}"/>

Your button would use it like this:

<button class="some class"  onclick="{!v.press}" >press me!</button>

The parent component would use it like this:

<c:CmpButton press="{!c.someComponentMethod}"/>
2
  • Aura.Action is not very well documented eh Aug 29, 2016 at 16:58
  • Seems not at all according to Google ... Let's hope they won't disable it with LockerService ... google.fr/… Aug 30, 2016 at 21:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .