In our last post we talk about Lightning Component Event for Component communication. In this post we will talk about how to do component communication with the help of <aura:method > . Aura:Method enables you to directly call a method in a component’s client-side controller instead of firing / handling a component event. With the help of <aura:method > we can call child component method from parent component.
Syntax :-
How to call method :- Simply call the function and pass parameter value in parent component
component.sampleMethod(arg1);
How to declare method :- Declare the aura:method with attribute
<aura:method name=”sampleMethod” action=”{!c.callAction}” description=”Sample”>
<aura:attribute name=”param1″ type=”String” default=”param1″/>
</aura:method>
Aura Method Action :- get the Aura:Attribute value with event.getParam(‘arguments’);
({
callAction: function(cmp, event) {
var params = event.getParam(‘arguments’);
if (params) {
var p1 = params.param1;
// add your code here
}
}
})