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)
最新推荐文章于 2025-09-02 10:34:58 发布
本文介绍了一个基于Angular的服务类,该服务利用RxJS的Subject实现组件间的数据通信。通过发布和订阅模式,实现了对选中点信息的有效传递。
2943





