I'm struggling to wrap my head around observables/observers/subjects and angular. I've looked through a number of tutorials covering observable basics and the basic subscription scenario makes sense. These tutorials do not seem to cover adding to observable collections however. Most of them also seem to focus on using the HttpClient, whereas I am trying to mock up some data without relying on a web service - just a basic in-memory array of objects for testing.
I've created a simple application to showcase my confusion.
Component 1 and Service 1 showcase a basic non-observable way of getting a collection of numbers and adding new numbers. Component 2 and Service 2 showcase a somewhat observable way of getting data and automatically getting updates due to subscription. I am using a Subject to do that.
https://github.com/rpasechnikov/observable-test-app
Would anyone be able to point out whether I am on the correct path or am I completely misunderstanding the observable pattern? Do I need to use a Subject here or should I be able to stick to Observables? If so - how do I raise a next() notification from that? On top of that, does anyone have any ideas on why is the first this.subject.next()
not trigger an update, whereas further calls do?
Thanks heaps!!