Implementing the reactive style
As covered in Chapter 1, Introduction to Angular and Its Concepts, we should only subscribe to an observable stream to activate it. If we treat a subscribe
function as an event handler, then we're implementing our code imperatively.
Seeing anything other than an empty .subscribe()
call in your code base should be considered a sign of ditching reactive programming.
In reactive programming, when you subscribe to an event in a reactive stream, then you're shifting your coding paradigm from reactive programming to imperative programming. There are two places in our application where we subscribe, once in current-weather
, and the other in the city-search
component.
Let's start by fixing current-weather
, so that we don't drop back into imperative programming.
Binding to an observable with an async pipe
Angular has been designed to be an asynchronous framework from the ground up. You can get the...