14

I have service which connects with Subject() to do paging. I'm using next(newData) to pass to subject, which keeps things alive, now I need to use complete() on each ajax call and pass it to subject. but after doing one complete() I'm started get error.

I wanted to know, can we still pass Subject observables still next(newData) if once completed() is already been triggered?

Liam
  • 27,717
  • 28
  • 128
  • 190
Basit
  • 16,316
  • 31
  • 93
  • 154

1 Answers1

20

There is some information on subjects from a former question on stack overflow : here. I encourage you to review it.

About your specific question, subjects once completed cannot emit any longer. This is part of the contract they abide by. Depending on the logic and flow of your application, you might:

  • decide not to complete the subject (why indeed are you completing it if you still need it later on?)
  • create a new subject whenever you need one, but then you have to pass it to whoever needs it.
Community
  • 1
  • 1
user3743222
  • 18,345
  • 5
  • 69
  • 75
  • because the http request called sends a complete - not that I wanted it, and Kills my subject... and yes I do want to add items client side to the collection, and have the subject broadcast these to all component observers. – redevill Aug 31 '21 at 21:41
  • 2
    This claim: "subjects once completed cannot emit any longer" is actually wrong. A ReplaySubject still emits values to late subscribers even after it completed. Check [this blog post](https://medium.com/@martin.sikora/rxjs-subjects-and-their-internal-state-7cfdee905156) on more details on this topic. – Wilt Dec 01 '21 at 11:35
  • Well yes, but a `ReplaySubject` and a `Subject` are different things. So saying it's wrong is like saying an apple isn't a fruit because it's not orange coloured. – Liam Apr 06 '22 at 09:27