Hello Everyone can anyone pls help why I am not able to console.log(apexParam)
, I am not even getting any alert and my FireEvent
is also not getting fired
Cmp which is firing the event
HTML
<template>
<ul class="slds-has-dividers_bottom slds-has-block-links_space" >
<li class="slds-item board-item productRow">
<div class="slds-clearfix">
<div class="slds-float_left slds-align_absolute-center">
<a onclick={navigateToDetail} target="_blank">{account.Name}</a>
Accid id {account.Id}
</div>
<div class="slds-float_right slds-align_absolute-center">
<button class="slds-button slds-button_success" onclick={showRelatedList} name="contact">View Contacts</button>
<button class="slds-button slds-button_success" onclick={showRelatedList} name="Opportunity">View Opportunites</button>
</div>
</div>
</li>
</ul>
</template>
JS file
export default class AccSearchResultWithCon extends LightningElement {
@api account;
@wire(CurrentPageReference) pageRef;
showRelatedList(event){
let buttonName = event.target.name;
let accId = this.account.Id;
console.log('Account Id',accId);
console.log('Button Name',buttonName);
if(buttonName ==='contact' || buttonName ==='Opportunity'){
//alert('Button Name '+buttonName);
let apexParam = {
"aId" : accId,
"btName" : buttonname
};
console.log('This is the apex param ',apexParam);
alert(apexParam);
fireEvent(this.pageRef, 'relatedlist' , apexParam);
}
}
}
CMP who is subscribing the event
HTML
<template>
Hi this is the accont Id {accountId}
</template>
JS File
export default class RealtedListTable extends LightningElement {
@track accountId;
@wire(CurrentPageReference) pageRef;
connectedCallback() {
registerListener('relatedlist', this.relatedListHandler, this);
}
relatedListHandler(data){
let accid = data.aId;
this.accountId = data.aId;
console.log('This is the accId from Event',accid);
}
disconnectedCallback() {
unregisterAllListeners(this);
}
}