3

Is it possible to fire an event from a lightning web component and handle in another lightning web component which is not in containment hierarchy? This is achievable in Aura component using application event.

1 Answer 1

8

Yes. It can be achieved using the pub-sub model.

To communicate between components that aren’t in the same DOM tree, use a singleton library that follows the publish-subscribe pattern.

Refer to Communicate Between Components documentation for more details.

For example, if you add two components to a Lightning page in Lightning App Builder, use the pubsub module to send events between them.

You can find the pubsub module here on lwc-recipe

1
  • Thank you very much Jayant for your help. I was not aware of publish/subscribe modal but now I used this and it worked for me. Apr 3, 2019 at 7:11

You must log in to answer this question.

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