How to invoke methods on child components from parent components in LWC
When we break down functionality into a lot of small components and make it modular, there might be a necessity to invoke methods or functions on the child components from the parent components.
We will be looking at how to invoke such child methods.
Let us take a sample Lightning Web Component which accepts the user input via an input box and pushes it to the child component. In the child component, am trying to capitalise the input that user provided.
The catch is, the capitalisation happens when the user clicks on the button that’s on the parent component.
Here is the parent component.
This is the JS controller file of the child component. This will house the function that gets invoked from the parent component.
It's as simple as getting a reference to the child component custom tag on the parent component and then invoking the method using the dot notation.
Subscribe to Salesforce Casts
Get the latest posts delivered right to your inbox