RxJs: Incrementally push stream of data to BehaviorSubject<[]>

后端 未结 2 871
無奈伤痛
無奈伤痛 2021-01-04 01:04

Basically I\'m trying to inflate BehaviorSubject<[]> with array of data which will be loaded in chunks.

BehaviorSubject<[]> wil

2条回答
  •  伪装坚强ぢ
    2021-01-04 01:37

    You can use getValue() method to achieve what you want to do.

    Example:

    data = new BehaviorSubject([]);
    
    addData(foo:any):void{
      // I'm using concat here to avoid using an intermediate array (push doesn't return the result array, concat does).
      this.data.next(this.data.getValue().concat([foo]));
    }
    

提交回复
热议问题