@aabegg/broadcaster 中文文档教程
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'});
游戏说明:
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'); });
操作
说明:
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
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