ngx-broadcaster
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

NGX BROADCASTER LIBRARY

License: MIT

NGX BROADCASTER is a library that provides the service for Angular applications to access global emitted events from components, service etc..

Installation

npm install ngx-broadcaster

Refer NPM package here.

Usage

import { NgBroadcasterModule } from 'ngx-broadcaster';

@NgModule({
  declarations: [
    AppComponent,
    SampleComponent
  ],
  imports: [
    BrowserModule,
    NgBroadcasterModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }

Example

Sample.component.html

 
<button (click)="sendMessage()">Send Message</button>
 

Sample.component.ts

 
// Selector : app-component
 
constructor(private broadcaster:NgBroadcasterService) {}
 
ngOnInit() {}
 
sendMessage(){
    let data = {
        message:"Hello World"
    }
 
    this.broadcaster.emitEvent('test-event',data);
}
 

App.component.html

<h1>{{message}}</h1>
<br>
<app-sample></app-sample>

App.component.ts

 
public message:string;
 
constructor(private broadcaster:NgBroadcasterService){}
  
ngOnInit(){
    this.broadcaster.listen('test-event').subscribe(res=>{
        this.message = res.message;
    })
}
 

API Reference

Event Payload Interface

export interface EventPayload{
    eventName:string;
    eventData:any;
}

License

This project is licensed under the terms of the MIT license.

Further help

If you have ideas for more that should be on this page, let me know

/ngx-broadcaster/

    Package Sidebar

    Install

    npm i ngx-broadcaster

    Weekly Downloads

    6

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    36.9 kB

    Total Files

    26

    Last publish

    Collaborators

    • ansafans