@aabegg/broadcaster
v1.0.4
Published
Event-Service zum senden und empfangen von globalen Events
Downloads
25
Readme
Installation
npm install @aabegg/broadcaster
Benutzung
Der Broadcaster
muss im AppModule als Provider eingebunden werden.
import { NgModule } from '@angular/core';
import { Broadcaster } from '@aabegg/broadcaster';
@NgModule({
declarations: [],
imports: [],
providers: [
Broadcaster
]
})
export class AppModule { }
Event senden:
this._bc.broadcast('demoEvent', {hallo: 'welt'});
Beispiel:
import { Component, onInit } from '@angular/core';
import { Broadcaster } from '@aabegg/broadcaster';
@Component({
selector: 'demo-component',
template: '<div>demo</div>',
styleUrls: ['./demo.component.scss']
})
export class DemoComponent implements onInit {
constructor(private _bc: Broadcaster) { }
ngOnInit() {
this._bc.broadcast('demoEvent', {hallo: 'welt'});
}
}
Event empfangen:
this._bc.on('demoEvent').subscribe(() => { console.log('demoEvent'); });
Beispiel:
import { Component, onInit, onDestroy} from '@angular/core';
import { Broadcaster } from '@aabegg/broadcaster';
@Component({
selector: 'demo-component',
template: '<div>demo</div>',
styleUrls: ['./demo.component.scss']
})
export class DemoComponent implements onInit, onDestroy {
private _subscriber;
constructor(private _bc: Broadcaster) { }
ngOnInit() {
this._subscriber = this._bc.on('demoEvent').subscribe((data: any) => {
console.log(data);
});
}
ngOnDestroy() {
this._subscriber.unsubscribe();
}
}
Versionen
1.0.0
- Initiale Version