An application may share data between components. Consider a movie database application, where a Movies list or a single Movie object will be shared across the components. We need a service to serve the Movies list or a single Movie object as and when requested by any components.
First, let us create a movie service using Angular CLI. Execute the following command in the command prompt to generate boilerplate code for movie.service:
e:\Explore\packt\MovieDB>ng generate service Movie installing service create src\app\movie.service.spec.ts create src\app\movie.service.ts e:\Explore\packt\MovieDB>
Here, the Angular CLI has created two files, namely movie.service.ts and movie.service.spec.ts. The boilerplate code of the ...