You need to sign in to do that
Don't have an account?
Jaanu
Passing the variable to child component from parent component ? Child component is not getting the variable.
I have component A which is calling component B. I have to pass the variable to child component. For some reason child component is not getting the variable. Can someone help with this.
Comp A - Component
<c:Presample ParentId="{!v.samId}"/> ---> Presample (Comp B) is another lightning component which inturn calls url by passing the samId..which has apex class, which takes the samId for further processing. When I debug, the child component is not getting the variable SamId. Also I noticed, apex class is not @AuraEnabled. So, I had included in the upper class... still same issue. Do I have to include @AuraMethod for all the methods in the class ?
Also why the child component is not getting the variable ? I am following the sample ref # https://developer.salesforce.com/blogs/developer-relations/2017/04/lightning-inter-component-communication-patterns.html
Comp B - Controller
var url = '/apex/JSample?ParentId=' + SamId; (Note: ParentId variable is defined in CompB component. SamId is defined in Comp A component)
Comp A - Component
<c:Presample ParentId="{!v.samId}"/> ---> Presample (Comp B) is another lightning component which inturn calls url by passing the samId..which has apex class, which takes the samId for further processing. When I debug, the child component is not getting the variable SamId. Also I noticed, apex class is not @AuraEnabled. So, I had included in the upper class... still same issue. Do I have to include @AuraMethod for all the methods in the class ?
Also why the child component is not getting the variable ? I am following the sample ref # https://developer.salesforce.com/blogs/developer-relations/2017/04/lightning-inter-component-communication-patterns.html
Comp B - Controller
var url = '/apex/JSample?ParentId=' + SamId; (Note: ParentId variable is defined in CompB component. SamId is defined in Comp A component)
In the Child Component (B) :
Did you have the attribute to get the value from parent?
As like below:
<aura:attribute name="ParentId" type="String"/>
if the above line is not presented then please include that and in child component Js you can assess the value by using component.get('v.ParentId')
so now you can pass the value to apex class
var action = cmp.get("c.serverEcho"); // use the class method name
action.setParams({ Id : component.get('v.ParentId') });
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C
All Answers
In the Child Component (B) :
Did you have the attribute to get the value from parent?
As like below:
<aura:attribute name="ParentId" type="String"/>
if the above line is not presented then please include that and in child component Js you can assess the value by using component.get('v.ParentId')
so now you can pass the value to apex class
var action = cmp.get("c.serverEcho"); // use the class method name
action.setParams({ Id : component.get('v.ParentId') });
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C