Skip to main content Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.

Hello community , 

 

I have 2 components - componentA(parent) and component B(child) 

 

when I pass data from parent to child , data is not visible. 

 

can anyone explain why ? 

 

component A html - 

 

<template>

    <lightning-card label="component A - parent">

        <p>Hi.I am component A.Parent</p>

        <c-component-B>

            {property1}="hi.I am component B.child component"

            {property2}="Welcome"

        </c-component-B>

    </lightning-card>

</template>   

 

component A js - 

 

import { LightningElement } from 'lwc';

 

export default class ComponentA extends LightningElement {

   

 

component B html - 

 

<template>

    <lightning-card>

       <p>message passed from {property1}</p>

       <p>message passed from {property2}</p>

    </lightning-card>

</template> 

 

component B js - 

 

import { LightningElement,api} from 'lwc';

 

export default class ComponentB extends LightningElement {

 

    @api property1;

    @api property2;

 

 

can anyone suggest something ?? 

 

#Developer Forums  #Trailhead Challenges  #Trailhead  #Data Management  #LWC  #LWC Development  #Sales Cloud  #Salesforce Developer  #Salesforce Admin

1 answer
  1. Today, 12:35 AM

     In LWC, to pass data from a parent to a child, you use the @api decorated properties in the child component and bind them using standard HTML attribute syntax

    (e.g., property1="value"), not the curly brace notation you’ve used. The curly braces {} are used for expressions or data binding within the same component, not for passing props directly. 

     

    component A html - 

     

    <template>    <lightning-card label="Component A - Parent">        <p>Hi. I am Component A. Parent</p>        <c-component-b property1="Hi. I am Component B. Child component" property2="Welcome"></c-component-b>    </lightning-card></template>
0/9000