▶ Check out my gear on Kit: https://kit.com/codewithsrini
Services is a type of category that surrounds by providing features that an app needs.
Service is simply a typescript class with a well defined purpose.
To increase modularity to your app, Angular distinguishes components from services
This is also known as separation of concerns.
A components primary job is to interact with template and nothing more.
A component mediates between the template and application logic by binding fields, properties and methods to our template.
Like a Component, there are certain task that a Component can delegate, such as fetching data from server, validating input data, or sending a data to server.
These type of task can be handled by a separate class in our Angular. And that class is called Service
Table of Contents:
***********************
00:06 - What is a Service?
04:33 - Creating a Service
08:22 - Dependency Injection
10:50 - Singleton Pattern
12:21 - Creating a Service with Angular CLI
13:23 - Injectable
17:19 - Conclusion
Source Code:
******************
https://stackblitz.com/edit/creating-a-service