0.0.1 • Published 5 years ago

ngx-broadcaster v0.0.1

Weekly downloads
6
License
MIT
Repository
-
Last release
5 years ago

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

0.0.1

5 years ago

1.0.0

5 years ago