Dec 3, 2016

Sujesh Ramachandran

Pass parent component controller method reference to child component

Just a month to go for new year '17 and wanted to somehow keep my technical stuffs improving, so here is a technique to pass a method reference to a component as attribute. 

Assume that you have a 'Parent Component', from Parent Component we are calling a child component to do something, after the child component execution, if you want to do any action like refresh the parent component, then we could use this technique to pass the reference of parent controller method to the child component and execute the parent controller method from child controller/helper methods. Even you could pass param to the parent component controller method from child component controller method.

So now lets see with an example how to pass the reference of parent component controller methods to the child component and execute the parent component controller method from child component helper methods. For this we are going to create a parent component which will have a button. On click of button, will show child component(modal popup). on click of 'ok' button in child component, will show a message in parent component, wherein message is passed from child component.

In this example I am passing just a string to the parent component from child component, but you could pass any data type supported by aura:attrubute in lightning.

Here is the output:

Screenshot 1

Screenshot 2

Screenshot 3

Follow me @ramsujesh

Sujesh Ramachandran

About Sujesh Ramachandran -

Co-Founder @ Fingertipplus Technologies | Co-Organizer of Coimbatore Salesforce Developer Group | Full Stack Coder | Blogger

Subscribe to this Blog via Email :


Write comments
December 04, 2016 6:48 PM delete

Well explained.. Looking for more lightning examples

January 25, 2023 12:56 PM delete

You can share your 3D printing ideas on sites like Thingiverse and Pinshape. You can also create your individual 3D printing and design portfolio Hand Massager web site to share your 3D printing ideas with the world. The steampunk, mechanical, chook design provides this clock a really distinctive look.