Overriding Service Implementation
Learn about the various techniques for providing and configuring services in Angular to control the injection of dependencies and settings within components.
We'll cover the following
We learned that a component could share its dependencies with its child components. Consider the FavoritesComponent
, where we used the slice
pipe to display a list of favorite products in its template. What if it needs to get data through a trimmed version of ProductsService
and not directly from the service instance of ProductListComponent
? We could create a new FavoritesService
that would extend the ProductsService
class and filter out data using the native slice
method of the array instead of the pipe. The favorites.service.ts
file would look like the following:
Get hands-on with 1400+ tech skills courses.