0

My parent JS code is:

    @api recordId;

        getMapData(){
                fetchdata()
                    .then(result => {
                        this.data = result;
                        this.error = null;
                        console.log('Data Connected callback' + JSON.stringify(this.data));
                        this.recordId = this.data[0].Id;
                    })
                    .catch(error =>{
                        this.error = error;
                        this.errorMsg = error;
                        this.isEmpty = true;
                    });  
            }
connectedCallback(){
        this.getMapData();
    }

Parent HTML :

<template>
   <c-map-field-table get-id-from-parent={recordId} ></c-map-field-table>
</template>

Child JS :

@api getIdFromParent;

getIdFromParent value is 'undefined'

3
  • What is the context of how recordId is populated on the parent? Is it on a record detail page?
    – stackasaur
    May 8, 2020 at 13:29
  • No @stackasaur, as you can see above the recordId is getting populated from the data returned from Apex method call. May 8, 2020 at 13:50
  • @stackasaur I forgot to check the recordId before sending it to the child component. Now its working. May 8, 2020 at 13:54

1 Answer 1

2

Did you check if recordId is defined before leaving parent component?

<template if:true={recordId}>
    <c-map-field-table get-id-from-parent={recordId} ></c-map-field-table>
</template>
2
  • Yes it worked. @Klecool May 8, 2020 at 13:53
  • I added a check to show the child component only when its parameters are filled. Thanks a bunch
    – Usman
    Nov 19, 2022 at 17:34

You must log in to answer this question.

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