Created
June 21, 2019 20:24
-
-
Save JitendraZaa/bd9183a99e4e23507bafb0f951ced038 to your computer and use it in GitHub Desktop.
Fire Pub-Sub event in Lightning Web Components
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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