Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!-- 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
You can’t perform that action at this time.