Creating a shared service to provide data to multiple pages

When you develop an app that involves a lot of pages and communication to the backend, you will need to have a way to communicate across pages and components. For example, you may have a service to request user data from the backend and store it in a common local service. Then, you will need to provide a way for the user to update their user data and see the update in real time. When the user navigates to different pages, the same information will be pulled and rendered too, without making multiple trips to the backend. This is a very common scenario that requires the use of the @Injectable decorator in Angular.

Observe the following screenshot of the app you will build:

The user can fill out the form and see updates on it in real time. Then, they can move to the next page (Go to Page 2) and see the following screenshot:

This page uses the same service as the preceding page and references the same date with the name and age. You will learn the following topics in this section:

  • Creating a service using @Injectable
  • Sharing a service across multiple pages
  • Detecting changes using getters and setters inside the service
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.103.183