@jakubforman/ngx-events
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

NgxEvents

This library was generated for allow you to use broadcast and listeners anywhere in Angular app.

Install

# For Angular 13
npm i @jakubforman/ngx-events@2.0.0

# For Angular 12
npm i @jakubforman/ngx-events@1.0.1

How to use it

Import lib

import {NgxEventsService} from '@jakubforman/ngx-events';

Basic example of use

export class AppComponent {

    constructor(
        private eventsService: NgxEventsService
    ) {

        // Create listener for global use and for remove
        const exampleListener = (data: any | { exampleKey: string }) => {
            console.log(data.exampleKey)
        }

        // Get every brodcast onlistener
        this.eventsService.on('example', exampleListener)
        this.eventsService.on('example', function (data: any | { exampleKey: string }) {
            console.log(data.exampleKey)
        })

        // brodcast in anywhere and send data to every listener with `example`
        this.eventsService.broadcast('example', {exampleKey: "exampleValue"}) // send to 2 listeners
        this.eventsService.broadcast('user-create', {user: {...}}) // send to 0 listeners


        // remove listener
        this.eventsService.off('example', exampleListener)

    }
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.0
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i @jakubforman/ngx-events

Weekly Downloads

0

Version

2.0.0

License

none

Unpacked Size

66.5 kB

Total Files

12

Last publish

Collaborators

  • jakubforman