passing values from child component to parent component in lwc -- w3web.net

A small example of custom event & dispatch event where we define a custom event in child component and passing values from child component to parent component in — LWC | how to pass value from child to parent component in lwc

467 views

Hey guys, today in this post we are going to learn about How to define a custom event in child lightning web component and passing values from child component to parent component in — LWC

Files we used in this post example:-

lwcParent.html Lightning Web Component HTML Template HTML file for used to write HTML element for user interface.
lwcParent.js Lightning Web Component JavaScript It is holding child component and it’s value.
lwcParent.js-meta.xml XML Meta File It is used for where this lightning web component you want to exposed.
lwcChild.html Lightning Web Component HTML It is child HTML file and calling on lwcParent.html.
lwcChild.js Lightning Web Component JavaScript It is holding @api public property with handler change functionality and it’s calling into parent componet.
lwcChild.js-meta.xml XML Meta File It is used for where this lightning web component should be exposed.
eventApplwc.app Lightning Application It is used for call the parent component to preview on browser.

Live Demo

passing values from child component to parent component in lwc -- w3web.net

Other related post that would you like to learn in LWC

Start lwcParent Component

Step 1:- Create Lightning Web Component : lwcParent.html

SFDX:Lightning Web Component >> New >> lwcParent.html

lwcParent.html [Lightning Web Component HTML]

Step 2:- Create Lightning Web Component : lwcParent.js

SFDX:Lightning Web Component >> New >> lwcParent.js

lwcParent.js [LWC JavaScript File]

Step 3:- Create Lightning Web Component : lwcParent.js-meta.xml

SFDX:Lightning Web Component >> New >> lwcParent.js-meta.xml

lwcParent.js-meta.xml [LWC Meta Data XML]

Start lwcChild Component

Step 4:- Create Lightning Web Component : lwcChild.html

SFDX:Lightning Web Component >> New >> lwcChild.html

lwcChild.html [Lightning Web Component HTML]

Step 5:- Create Lightning Web Component : lwcChild.js

SFDX:Lightning Web Component >> New >> lwcChild.js

lwcChild.js [LWC JavaScript File]

Step 6:- Create Lightning Web Component : lwcChild.js-meta.xml

SFDX:Lightning Web Component >> New >> lwcChild.js-meta.xml

lwcChild.js-meta.xml [LWC Meta Data XML]

Start Application Component

Step 7:- Create Lightning Application : eventApplwc.app

From Developer Console >> File >> New >> Lightning Application

eventApplwc.app [Component Application File]

passing values from child component to parent component in lwc -- w3web.net

Further post that would you like to learn in LWC

 

 

FAQ (Frequently Asked Questions)

What is custom event LWC?

Custom events are used for communication in lightning web components. First, the comparison with Aura Components. In Aura component, we need to create a separate event file and need to register the event, where event is fired. LWC uses standard DOM events to create and dispatch events.

What is bubble event in LWC?

When we create an event, bubbles and composed define the event propagation behavior. In this behavior, the event bubbles up the DOM, but don't cross the shadow boundary. In simple terms, It bubbles up inside the current template, in which event is fired, but it would not cross it's boundary.

What is dispatch event?

dispatchEvent is what you call if you want to send or trigger an event. Internally, the browser is doing this whenever the user rotates their device, which triggers orientationchange. In this specific example, you don't need to trigger this manually unless you need to do so for testing.

Related Topics | You May Also Like

  • Your reaction of the article ▾
 

Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

12 thoughts on “A small example of custom event & dispatch event where we define a custom event in child component and passing values from child component to parent component in — LWC | how to pass value from child to parent component in lwc”

  1. Hi. your post is so nice and I really loved reading your post.
    It was very well authored and easy to understand. Great Thanks for sharing awesome info. I really love to read your blog.

    Reply

Leave a Comment