function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Flint LockwoodFlint Lockwood 

Reusing Functions Salesforce Lightning

Is there a way for one component to reference the functions in another without embedding?

If I have to embed the component, how do I reference there parent function from a  child component and vice versa?
Pankaj MehraPankaj Mehra
Hi Flint,

You can do this 2 ways :

Create a parent component and extend in child component
<aura:component implements="forceCommunity:availableForAllPageTypes" controller="PC_CreateCaseController" extends="c:PC_CreateCasePage" access="global">

This was you can call parent component method

Second way is to use application level events, create 2 events and fire a event from child and handle it in parent upon event received call the method of your choice and when finished fire a event from parent that gets handled in child. You can transport data through event's attribute.

Flint LockwoodFlint Lockwood
For the second option, how do I fire the parent event from the child?
Flint LockwoodFlint Lockwood
For the first option, after I extend the parent component, is the syntax to call the parent method : "super.methodname"?
Pankaj MehraPankaj Mehra
Hi Flint,

Second Option
There is no parent event and child event , there is only application event, parent and child components both can fire a event and both can handle a event, to fire a parent method from child simply fire a event from child , handle it in parent and once it is captured in parent call respective method.

First option:
You do not need to add super keyword just call the method as its in same component

brahmaji tammanabrahmaji tammana

Just to add, You also need add extensible attribute at aura:component (parent) level.


<aura:component extensible="true" />  <--- parent component



Dogan Turkcan 9Dogan Turkcan 9