From the course: Learning RxJS

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Subscribing to changes using subjects

Subscribing to changes using subjects

From the course: Learning RxJS

Subscribing to changes using subjects

- [Instructor] For historical reasons, we may want to keep a list of all the temperatures we changed our thermostat to. So if a user changed their thermostat from 45 degrees, 65 degrees and 73 degrees, we should be able to keep track of that. We'll be able to do this by subscribing to our observable and storing these data points in an array. If instead we want to start also displaying our Fahrenheit weather to Celsius, we can add a button that says start displaying Celsius. We can do this by adding a new subscription to our thermostat observable and begin showing weather in Celsius as well. For this use case, we'll want to use a regular subject. This is because we are not interested in the previous or the current values. We'll only start converting the values when the user clicks on our start displaying Celsius button. If you're wondering why we can't use a BehaviorSubject like before, it's because BehaviorSubjects will…

Contents