2

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.

6

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

  • 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. – Ajay Prakash Dubey Apr 3 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.