1

I work with trailhead unit Create a Child Component and Interact with It in Build a Bear-Tracking App with Lightning Web Components module.

The bearTile component triggers bearview event in this way:

handleOpenRecordClick() {
    const selectEvent = new CustomEvent('bearview', {
        bubbles: true
    });
    this.dispatchEvent(selectEvent);
}

in the class code there is also: @api bear;

And the top parent component gets the event having access to the bear property in the event object:

handleBearView(event) {
    // Navigate to bear record page
    this[NavigationMixin.Navigate]({
        type: 'standard__recordPage',
        attributes: {
            recordId: event.target.bear.Id,
            objectApiName: 'Bear__c',
            actionName: 'view',
        },
    });
}

I do not understand how it is possible while not declaring a new detail property of the CustomEvent instance.

Could any of you guide me on with that subject?

1 Answer 1

2

event.target is the element that dispatched the event. Therefore, anything that's an @api on the target can be accessed by any other component that can handle the event (by default, just the parent template). You don't need to specify a detail in this case. Note that @track and undecorated properties will not be accessible.

1
  • It makes sense. Thank you. Apr 21, 2019 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .