0

I have a parent LWC from where I have a list of records, If I call the data attributes in for loop from parent I'm able too see the output in UI:

Parent LWC html:

<template if:true={causerecs}>                        
        <template for:each={causerecs} for:item="cause">                        
            <p key={cause.Id}>                               
                {cause.Name}
            </p>
        </template>
    </template>

Able to see the values in the UI:

enter image description here

But if I call the child from parent and pass the values, In not able to capture the values and the console message shows undefined.

 <template if:true={causerecs}>                        
        <template for:each={causerecs} for:item="cause">                        
            <p key={cause.Id}>
                <c-gra_ra_cpcm_causedetailpage_lwc
                 reid={riskcausedetailrecord}
                 type={cause.Type__c}
                 legid={cause.GRA_Leg__c}
                 causename={cause.name}
                 >
                </c-gra_ra_cpcm_causedetailpage_lwc>
            </p>
        </template>
    </template>

Child LWC js:

@api type;
    @api legId;
    @api causename;
    @api reid;

    connectedCallback(){
        console.log('reId:::'+this.reid);
        console.log('this.name:::'+this.causename);
        console.log('this.legId:::'+this.legId);
    }

Child LWC html:

<template>
    <div>Entered from cause detail page</div>
    <div>{causename}</div>
</template>

enter image description here

Only able to see the message not the values: enter image description here

3
  • One typo in your code : for camel case property names like "legId" , use "leg-id" while assigning it from parent in markup.
    – Rohit
    Commented Apr 10, 2023 at 4:22
  • @Rohit , Thanks for the catch, able to get the legid now , also my cause.name is also case sensitive, added as cause.Name and it worked. Thanks for your help on this.
    – sfdcDev
    Commented Apr 10, 2023 at 5:04
  • Great ! You can add as answer for future reference.
    – Rohit
    Commented Apr 10, 2023 at 5:16

1 Answer 1

0

I corrected my code with exact field names and notations, as the code seems to be case-sensitive.

"legId" , use "leg-id" "cause.name" , use "cause.Name"

You must log in to answer this question.

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