Skip to content

Instantly share code, notes, and snippets.

@JitendraZaa
Created June 21, 2019 20:24
Show Gist options
  • Save JitendraZaa/bd9183a99e4e23507bafb0f951ced038 to your computer and use it in GitHub Desktop.
Save JitendraZaa/bd9183a99e4e23507bafb0f951ced038 to your computer and use it in GitHub Desktop.
Fire Pub-Sub event in Lightning Web Components
.ele1{
background-color: #BBB;
padding:50px;
border-radius: 25px;
margin-top:20px;
margin-left:10px;
margin-right:10px;
cursor: pointer;
}
.subComp{
background-color: #fff;
border-radius: 25px;
margin:10px;
padding:30px;
}
<template>
<div class="ele1">
Vehicle Component - {log}
<div class="subComp">
<c-tesla
onmodelclick={captEvent}></c-tesla>
</div>
<div class="subComp">
<c-honda> </c-honda>
</div>
</div>
</template>
import { LightningElement, track } from 'lwc';
import pubsub from 'c/pubsub' ;
export default class Container extends LightningElement {
@track log = '';
captEvent(evt){
this.log = this.log+' '+evt.detail;
pubsub.fire('uniqueEventId', evt.detail);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment