我有一个角度2服务,从API获取数据,这个服务有3个订阅者(在组件中定义),每个订阅者使用数据执行其他操作(不同的图表)
我注意到我正在向API发出三个GET请求,而我想要实现的是一个请求,并且订阅者将共享我看到HOT和COLD可观察的数据并尝试使用.share()可观察但我仍在进行3次个人通话
更新,添加代码
服务
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import {Observable} from 'rxjs/Rx';
// Import RxJs required methods
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { StationCompliance } from './model/StationCompliance';
@Injectable()
export class StationComplianceService {
private url = '/api/read/stations';
constructor(private http : Http) {
console.log('Started Station compliance service');
}
getStationCompliance() : Observable<StationCompliance []> {
return this.http.get(this.url)
.map((res:Response) => res.json())
.catch((error:any) => Observable.throw(error.json().error || 'Server Error'));
}
}
Run Code Online (Sandbox Code Playgroud)
组件1
import { Component, OnInit } from …Run Code Online (Sandbox Code Playgroud) 希望有人能帮助我解决这个问题。我有 2 个流,需要在其上使用操作符 mergeLatest。一段时间后,我需要动态添加还需要使用combineLatest 的流。这是我需要做的:
stream a ---------a---------------b-------------c------------------------>
stream b ----1--------2-----3-------------------------4------------------>
stream c (not defined at start) -----z-----------------x------------>
stream d (not defined at start) ----------k------>
(combineLatest)
result ---------(a1)(a2)--(a3)--(b3)----(b3z)-(c3z)-(c4z)-(c4x)-(c4xk)->
Run Code Online (Sandbox Code Playgroud)
更新
更具体地说,我想打开此STREAM(链接)

对于这个结果:
A----B---B0-C0--D0--D1--E1--E1a--F1a--F2a---G2a---G3a--H3a-H3b--I3b
Run Code Online (Sandbox Code Playgroud) 我有以下文件输入:
const file = document.getElementById('file');
file.addEventListener('change', e => {
console.log(e.target.files[0]);
});Run Code Online (Sandbox Code Playgroud)
<input id="file" type="file" />Run Code Online (Sandbox Code Playgroud)
我正在使用 XMing 从 WSL 运行 Emacs,它运行良好。我的问题是尝试在 Windows 和 WSL 之间共享文件夹时。我尝试了以下方法:
在列出的 3 个选项中,只有最后一个适用于 projectile(可能还有其他 Emacs 包)。但是我也需要能够从 Windows 访问/修改文件,所以这不是一个可行的选择。
有没有人为此找到好的解决方案?
上下文: Angular 4.x,RxJs 5.4.x,NgRx 4.1.1.
目标:当多个组件请求相同的数据时,我希望避免重复相同的api调用.我不想取消飞行中的请求,只是在飞行中的请求完成之前不要取得未来的请求.
方法:在商店中有一个名为的标志isFetching.在我的效果中,我检查标志,看看是否已经有飞行中的请求.如果是,那么我不提出请求.触发效果的相同操作会将isFetching标志设置为true.
问题:在运行效果之前更新状态.因此,isFetching发送的第一个请求之前,是真实的.所以没有发送任何请求.
示例:以下是问题的简化版本:
state.ts
export interface State {
isFetching: boolean;
}
Run Code Online (Sandbox Code Playgroud)
reducer.ts
export function reducer(state: State, action: Action): State {
switch (action.type) {
case 'FETCH':
return <State>{ isFetching: action.payload };
}
return state;
}
Run Code Online (Sandbox Code Playgroud)
effect.ts
@Effect()
public fetch: Observable<Action> = this.actions.ofType('FETCH')
.withLatestFrom(this.store.select(x => x.isFetching), (_, x) => x)
.filter(x => !x)
.switchMap(action =>
this.api.getData()
.map(data => new FetchSuccess(data))
.catch(() => Observable.of(new FetchFailure()))
);
Run Code Online (Sandbox Code Playgroud)
想法#1: …