angular4实现发布、订阅功能(基于observable)

import {Injectable} from "@angular/core";
import {Subject} from "rxjs/Subject";
import {Observable} from "rxjs/Observable";
@Injectable()
export class HisCurveAddService {

    private _selectedPoint: Subject<any> = new Subject<any>();

    public constructor() {
    }

  public setSelectedPoint(selectedPointsIfo: any): void {
        this._selectedPoint.next(selectedPointsIfo);

    }

    public currentSelectedPoint(): Observable<any> {
        return this._selectedPoint.asObservable();
    }


}

使用
//发布
this._hisCurveAddService.setSelectedPoint(arg)
//订阅
this._hisCurveAddService.currentSelectedPoint().subscribe((value: any)=>{console.log(value)});




你可能感兴趣的:(angular4实现发布、订阅功能(基于observable))