@aabegg/broadcaster 中文文档教程

发布于 8年前 浏览 22 更新于 3年前

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
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文