-1

I have 2 components.

  • Component 1 contains method1,

  • Component 2 contains method2.

My question is : At the time of method2 call in component2. In method2, I have to call method1 is it possible ?

1 Answer 1

2

You can use Events to call.

Eg: component1 contains method1 that fire the event and it can handled by component2 and you can call method2 by handler . go through with Events

there ara several event type eg

1.APPLICATION EVENT

If your components have no communication you can go with Application Event

  <aura:Application >
       <c:component1 />
       <c:component2 />
    </aura:Application>
  • (In short because of using application event there is no communication between components).In these scenerio you can go with Application Event go through this link for Application Event

2.Component Event:

component1:

<aura:component>
  <c:component2 />
</aura:component>

If component2 fires the event it can be handled by component 2 as well as component 1 you can call methods by handler.Always try to use component event as possible because it is comunincationg within the components.its a best practice too.

3.Aura:method

If you want to call parent component to child component method best approach use <aura: method>

visit the link aura:method example

You must log in to answer this question.

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