0
IONICにオブザーバーパターンを実装する方法2.私はIONICにオブザーバーパターンを実装する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) {
}
}
私の質問は、このケースではどのようにオブザーバーのパターンを実装できますか?
私のサービスでは、このイベントを購読/非購読することができるコントローラを作成する必要があることは知っています。コントローラではnotifyメソッドを作成する必要がありますが、どのようにIONIC 2/RxJsで作成するのかわかりません
ありがとうございます!