Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用ReplaySubject,但仅回放最近的可观察项_Angular_Rxjs5 - Fatal编程技术网

Angular 使用ReplaySubject,但仅回放最近的可观察项

Angular 使用ReplaySubject,但仅回放最近的可观察项,angular,rxjs5,Angular,Rxjs5,我有一个这样的重播主题: matchCount = new ReplaySubject<number>(); totalCount = new ReplaySubject<number>(); getMatchedEventsCount(){ return this.dcs.matchCount.asObservable(); } getTotalEventsCount(){ return this.dcs.totalCount.asObs

我有一个这样的重播主题:

matchCount = new ReplaySubject<number>();
totalCount = new ReplaySubject<number>();
  getMatchedEventsCount(){
    return this.dcs.matchCount.asObservable();
  }

  getTotalEventsCount(){
    return this.dcs.totalCount.asObservable();
  }
我只是得到计数-我只需要每个重播主题的最后一个(最近的)值,我不需要所有的值


有办法吗?

指定要在构造函数中重播的事件数:

 new ReplaySubject<number>(1);
新的ReplaySubject(1);

指定要在构造函数中重播的事件数:

 new ReplaySubject<number>(1);
新的ReplaySubject(1);

我认为这意味着您正在寻找一个
行为主体
我认为您是对的-是否有某种方法可以异步设置行为主体的初始值?使用
未定义的
0
初始化它,然后设置初始值,就像您正在使用
RelaySubject
一样,我认为这意味着您正在寻找
BehaviorSubject
我认为您是对的-是否有某种方法可以异步设置行为主体的初始值?使用
undefined
0
初始化它,然后设置初始值,就像使用
RelaySubject