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)});




相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页