Search Here

Parent to child component

parentCmp.html

<template>
  Hey!! this is my name from the parent component :
 <c-child name={myname}></c-child>
</template>
...................................................................................................................................................

parentCmp.js

import { LightningElement } from 'lwc';

export default class ParentCmp extends LightningElement {
   myname = 'SalesforceKid';
}
..................................................................................................................................................

child.html

<template>
 {name}
</template>
.....................................................................................................................................................
child.js

import { LightningElement, api } from 'lwc';

export default class ParentCmp extends LightningElement {
   @api name;
}
----------------------------------------------..............................................................................................

Output :
----------------------------------------------
Hey!! this is my name from the parent component :
SalesforceKid


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.