ExamGecko
Question list
Search
Search

Question 1 - Certified B2B Commerce Developer discussion

Report
Export

A developer needs to create an event listener on a parent component programmaticallv. With the script below, what should replace the text <EVENT LISTENER UNE>?

A.
this.template.addEventListener(handleNotification);
Answers
A.
this.template.addEventListener(handleNotification);
B.
this.template.addEventListener(this.handleNotification);
Answers
B.
this.template.addEventListener(this.handleNotification);
C.
this.template.addEventListenerCnotification1, this.handleNotification);
Answers
C.
this.template.addEventListenerCnotification1, this.handleNotification);
D.
addEventListener('notifJcatiorV, this.handleNotification);
Answers
D.
addEventListener('notifJcatiorV, this.handleNotification);
Suggested answer: C

Explanation:

To create an event listener on a parent component programmatically, the developer should use the following line of code:

this.template.addEventListener('notification', this.handleNotification);

This line of code adds an event listener to the template element of the parent component, which is the root element that contains all the child elements. The event listener listens for an event named 'notification', which is a custom event that can be dispatched by any child component. The event listener invokes a method named handleNotification, which is an arrow function defined in the parent component class. The handleNotification method receives the event object as a parameter and can perform any logic based on the event data. The other lines of code are either incorrect or incomplete. Salesforce

Reference: Lightning Web Components Developer Guide: Communicate with Events, Lightning Web Components Developer Guide: Create and Dispatch Events

asked 23/09/2024
Prenolan Kamiah
41 questions
NextNext
User
Your answer:
0 comments
Sorted by

Leave a comment first