Angular 6 + RxJS 6.0 : How to push new element to array contained by Observable

前端 未结 2 1619
野趣味
野趣味 2021-02-15 15:52

I am receiving data from firebase server in chunks while rendering that data requires a library which insists on observable contains Array. I am somehow unable to push a new dat

2条回答
  •  爱一瞬间的悲伤
    2021-02-15 16:04

    In addition to GeoAstronaute's answer, here's how I would remove stuff from the array:

      removeElementToObservableArray(idx) {
        this.array$.pipe(take(1)).subscribe(val => {
          const arr = this.subject.getValue()
          arr.splice(idx, 1)
          this.subject.next(arr)
        })
      }
    

    I.E: your ngforloop in the HTML could have the let i = index, which would provide an index to the data you wanted to remove. Secondly, the remove function has to be inside the ngforloop tag :-)

提交回复
热议问题