Chapter 6. Reactive programming in Angular
This chapter covers
- Handling events as observables
- Using observables with Angular Router and forms
- Using observables in HTTP requests
- Minimizing network load by discarding unwanted HTTP responses
The goal of the first five chapters was to jump-start your application development with Angular. In those chapters, we discussed how to generate a new project from scratch, covering modules, routing, and dependency injection. In this chapter, we’ll show you how Angular supports a reactive style of programming, in which your app reacts on changes either initiated by the user or by asynchronous events like data arriving from a router, form, or server. You’ll learn which Angular APIs support data push and allow you to subscribe to RxJS-based observable data streams.
Note
If you’re not familiar with RxJS library concepts such as observables, observers, operators, and subscriptions, read appendix D before proceeding with this chapter.
Angular offers ready-to-use observables for implementing various scenarios: handling events, subscribing to the route’s parameters, checking the status of a form, handling HTTP requests, and more. You’ll see some examples of using Angular observables, but each of the following chapters contains reactive code as well.