Activity Forums Salesforce® Discussions What is the Use of Aura:method tag in Salesforce?

  • Nikita

    Member
    August 22, 2019 at 10:43 am

    Hi Achintya,

    Use <aura:method> to define a method as part of a component's API. This enables you to directly call a method in a component’s client-side controller instead of firing and handling a component event. Using <aura:method> simplifies the code needed for a parent component to call a method on a child component that it contains.

    For more detail you can refer https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_tag_method.htm

  • Deepak

    Member
    August 22, 2019 at 12:48 pm

    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
    }
    }
    })

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos