Skip to content

Instantly share code, notes, and snippets.

@douglascayers
Last active December 30, 2018 05:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save douglascayers/1b239e90446eb93a5a6826535124fd61 to your computer and use it in GitHub Desktop.
<!-- ServiceComponent.cmp -->
<aura:component>
<aura:method name="sum" action="{!c.handleSum}">
<aura:attribute name="a" type="Integer" required="true"/>
<aura:attribute name="b" type="Integer" required="true"/>
</aura:method>
</aura:component>
/* ServiceComponentController.js */
({
handleSum: function(component, event, helper) {
const params = event.getParam( 'arguments' );
return ( params.a + params.b );
}
})
<!-- TryServiceComponent.cmp -->
<aura:component>
<c:ServiceComponent aura:id="serviceComponent"/>
<lightning:button label="Add Numbers" onclick="{!c.handleClick}"/>
</aura:component>
/* TryServiceComponentController.js */
({
handleClick: function(component, event, helper) {
const service = component.find("serviceComponent");
let sum = service.sum(2, 3);
console.log(sum); // 5
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment