Using aura:method to call child methods from parent methods

The aura:method command is a very useful utility that allows for defining methods in the child component API, so that a parent component can call the method directly, without having to create event files.

Let's look at the following sample code to understand the syntax.

Let's create a child component with the aura method, as follows, and name the component childMethodCmp:

<aura:method name="sampleMethod" action="{!c.doAction}"  description="Sample method with parameters">  <aura:attribute name="param1" type="String" default="parameter 1"/>  <aura:attribute name="param2" type="Object" /> </aura:method>/* auraMethodController.js */({ doAction : function(cmp, event) {  var params = event.getParam('arguments'); ...

Get Learning Salesforce Lightning Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.