0

I have written the below code where in the parent component, I have defined a lightning button to get the values from aura method defined in child component: The lightning button in my parent component is not showing the alert pop up with the value from method.

Below is my code:

ChildComp:

<aura:component>
    <aura:method name="child" action="{!c.handleChild}" access="public">
        <aura:attribute name="param1" type="String"/>
    </aura:method>
</aura:component>

ChildCompController:

({
    handleChild : function(component, event, helper) {
        var params = event.getParam('arguments');
        console.log("++++++++++",params);
        if(params){
            var param1=params.param1;
            alert(param1);
        }
    }
})

Parent Comp:

<aura:component >
    <c:ChildComp aura:id="childComp"/>
    <lightning:button name="Invoke Child action" label="Invoke Child action" onClick="{!c.doClick}"/>
</aura:component>

ParentCompController:

({
    doClick : function(cmp, event) {
        var cc=component.find('childComp');
        cc.child('I am from parent comp');
    }
})

1 Answer 1

3

2 Issues:

In parent component markup change onClick to onclick

<lightning:button name="Invoke Child action" label="Invoke Child action" onclick="{!c.doClick}"/>

In parent component controller: change component.find to cmp.find

doClick : function(cmp, event) {
var cc=cmp.find('childComp');

Learning Suggestion: Also Since you are learning Try to troubleshoot these issues using chrome dev tools by putting breakpoints which will help you understand and fix these issues yourself

1
  • thanks, the main issue was onclick. i was using onClick that was causing the issue.
    – Ankur ---
    May 14, 2019 at 10:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .