Parent to Child Passing Data Value
public class DisplayAccountRecordsget{
public static list<contact> getAccountRecords(){
return [select id,lastname,firstname,phone from contact limit 10];
}
}
parenttochildpassdata js
-----------------------------
import {LightningElement} from 'lwc';
import getrecords from '@salesforce/apex/DisplayContactRecordsget.getContactRecords';
export default class parenttochildpassdata extends LightningElement {
datadisplayed
@wire(getrecords)
datawire({data,error})
if(data){
this.datadisplayed = data;
} else if(error){
console.log('Error feacting data from Apex:'+error);
}
parenttochidpassdata html
<template>
<lightning-card>
<c-childtoparentpassdata contacts = {datadisplayed}><c-childtoparentpassdata>
</lightning-card>
</template>
childtoparentpassdata js
import {lightningElement , api} from 'lwc';
export default class childtoparentpassdata extends LightningElement {
@api contacts
}
childtoparentpassdata html
<template>
<lightning-card variant="Narrow" title="Parent to Child" icon-name="standard:contact">
<template if:true={contacts}>
<template for:each={contacts} for:item = "conlist">
<li key={conlist.id}> Contact FirstName - {con.FirstName}
Contact LastName - {con.LastName}
Contact Phone - {con.Phone}</li>
</template>
</lightning-card>
</template>
No comments:
Post a Comment