Error with Events lwc - [NoErrorObjectAvailable] Script error

for your event there is no so you are receiving this error. You should instead change to event.detail and use your detail. I would suggest restructuring the event that you are sending however to be:

this.dispatchEvent( new CustomEvent( 'press', { detail: { value: this.sGreetingToParent }} )

and then access it in your method by getting event.detail.value as you have now set this with a key for the attribute that you wish to receive. just assigning event.detail with the value will set detail to an object and the key would not exist for what you wish to receive.

also as mentioned in another response here, you should make sure that your javascript expressions match the case for their usage:

showGreeting is not the same as showgreeting. Javascript being case sensitive, you will want to have your onpress={showGreeting}

You may also consider some checks in place too in your method that shows the greeting, there are two ways to do it. One is new, one is old.


this.sGreeting = ( event && event.detail && event.detail.value ) || '';

New: (not as widely supported in all browsers yet)

this.sGreeting = event?.detail && event?.detail?.value

Looks like there is small typo in your parent component when you handle the event

Change the code to below , notice i have showGreeting instead of showgreeting

<c-child-comp-dispatch onpress={showGreeting}></c-child-comp-dispatch>