Using the switchMap operator to switch the last subscription with a new one
For a lot of apps, we have features such as searching content as the user types. This is a really good user experience (UX) as the user doesn't have to press a button to do a search. However, if we send a call to the server on every keyboard press, that's going to result in a lot of HTTP calls being sent, and we can't know which HTTP call will complete first; thus, we can't be sure if we will have the correct data shown on the view or not. In this recipe, you'll learn to use the switchMap
operator to cancel out the last subscription and create a new one instead. This would result in canceling previous calls and keeping only one call—the last one.
Getting ready
The project that we are going to work with resides in chapter05/start_here/using-switchmap-operator
, inside the cloned repository.
- Open the project in VS Code.
- Open the Terminal and run
npm install
to...