Angular TutorialLesson 24Free preview
Angular Services & DI
This lesson is part of Angular · All levels
Summary
A service is a class of logic or data that can be used together by many components. Through dependency injection, you just inject the service through the constructor without making a manual instance. This approach prevents code duplication and makes testing easier.
Key points
- Service provided by the decorator @Injectable
- ProvidedIn: 'root' makes the service singleton app
- Dependence injection is performed through the constructor
- Service is suitable for HTTP logic, state, and shared utility
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.