Package Exports
- ngx-global-events
- ngx-global-events/bundles/ngx-global-events.umd.js
- ngx-global-events/fesm2015/ngx-global-events.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ngx-global-events) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ngx-global-events | Angular6+
A really simple way to emit and listen global events in Angular 6+.
Installation
$ npm i ngx-global-events --save
How to use?
To import:
// component.ts
import { NgxGlobalEventsService } from 'ngx-global-events';
constructor(
private globalEventsService: NgxGlobalEventsService
) { }
To emit:
// without data
this.globalEventsService.get("anyEventWithAName").emit();
// or
this.globalEventsService.emit("anyEventWithAName");
// with data
const dataToEmit = "Hello world!";
this.globalEventsService.get("anyEventWithAName").emit(dataToEmit);
// or
this.globalEventsService.emit("anyEventWithAName", dataToEmit);
To listen:
// without data
this.globalEventsService.get("anyEventWithAName").subscribe(() => {
// code to do when listen something
});
// with data
this.globalEventsService.get("anyEventWithAName").subscribe((data) => {
console.log(data); // "Hello world!";
// code to do when listen something
});
On any event:
this.globalEventsService.onEvent.subscribe((data: NgxGlobalEvent) => {
// code to do when listen something
})
// NgxGlobalEvent
// {
// eventName: 'name of event - is a string',
// data: ['data emitted - is anything']
// }