I am new to lwc. I have a method in the child component which returns a string. I called the child method from the parent components but it fails to return the string to the parent component. Did I miss something?
child.js
@api
get myName(){
console.log("child method myName");
return "My name is Raj";
}
parent.html
<c-child></c-child>
<button onclick={callChildMethod}>Call Child Method</button>
parent.js
callChildMethod() {
let childCmp = this.template.querySelector('c-child');
let myName = childCmp.myName();
console.log("Child name " + myName);
}
Thanks in advance.