Newer Version Available
Calling Component Methods
Communicate Between Components
Use aura:method to communicate down the containment hierarchy. For example, a parent component calls an aura:method on a child component that it contains.
To communicate up the containment hierarchy, fire a component event in the child component and handle it in the parent component.
Syntax
Use this syntax to call a method in JavaScript code.
cmp is a reference to the component.
sampleMethod is the name of the aura:method.
arg1, … argN is an optional comma-separated list of arguments passed to the method. Each argument corresponds to an aura:attribute defined in the aura:method markup.
Using Inherited Methods
A sub component that extends a super component has access to any methods defined in the super component.
An interface can also include an <aura:method> tag. A component that implements the interface can access the method.
Example
Let's look at an example app.
c:auraMethodCallerWrapper.app contains a c:auraMethodCaller component.
c:auraMethodCaller is the parent component. c:auraMethodCaller contains the child component, c:auraMethod.
We'll show how c:auraMethodCaller calls an aura:method defined in c:auraMethod.
We'll use c:auraMethodCallerWrapper.app to see how to return results from synchronous and asynchronous code.