You can use the @api annotation to expose a method from a child component to the parent component's controller logic. Component method calls are basically a way to communicate downward through your component's structure, in contrast to events (described in the next section), which can be used to communicate upward.
Methods can return values and/or accept parameters as per normal JavaScript programming semantics. Note that @api only exposes methods to other components in your package and not to components defined by your customers. The following is a basic example:
@api
myMethod(myParameter) {
return 'somevalue';
}
In this next example, the logic in a parent component controller is using the standard browser querySelector method to obtain a reference to a child component. Once an instance of the child component is returned, the code then calls the exposed method directly as usual. The following snippet searches for a child component with the HTML tag name of lightning-datatable and returns the first one found:
var selectedRows =
this.template.querySelector(
'lightning-datatable').getSelectedRows();