0
我想要實現離子觀察者模式2如何離子實現觀察者模式2
我有這樣的服務
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Events } from 'ionic-angular';
@Injectable()
export class ExampleService {
private _events: Events;
constructor(public http: Http, events: Events) {
this._events = events;
}
doStuff() {
this.raiseBeginDownloadData('data');
}
private raiseBeginDownloadData(hash: string){
this._events.publish('begin-download', hash);
}
}
這是我的控制器:
import { Component } from '@angular/core';
import { NavController, AlertController, Platform } from 'ionic-angular';
import { ExampleService } from '../../providers/example-service';
@Component({
selector: 'page-exaple',
templateUrl: 'example.html',
providers: [ExampleService]
})
export class MyPage {
constructor(public navCtrl: NavController, platform: Platform, public alertCtrl: AlertController, public eventSvc: ExampleService) {
}
}
我的問題是,在這種情況下,我如何實現觀察者模式?
我知道,在我的服務中,我需要創建一個方法,使控制器訂閱/ unscribed這個事件;並在控制器中,我需要創建一個通知方法,但我不知道如何使它與IONIC 2/RxJs
非常感謝!