Module 05 of 10

Services & Dependency Injection

Lessons

About This Module

Components should focus on the template and user interaction, not on fetching data or holding business logic. Angular's answer is the service: a plain class that holds shared logic or state, and dependency injection (DI), the system that hands that class to whoever asks for it instead of making each component build its own.

It starts with creating a service with the @Injectable decorator and the providedIn: 'root' option, which makes one shared instance available across the whole app. From there it covers the inject() function and constructor injection for requesting a dependency, and providers: how Angular decides what to hand over, including InjectionToken for non-class values and how the injector hierarchy lets a component get its own instance of a service.

Some of these videos were recorded for earlier Angular versions, so they may show constructor injection and NgModule providers where newer code uses inject() and standalone components. The ideas behind services and DI are the same. Watch the lessons in order, then continue on to Routing & Navigation.

Lessons

4 videos
01

Angular 17: Services and Dependency Injection

A guide to what services are in Angular, how to create one, and how dependency injection delivers it to your components.

02

Build a Full Angular Application, Episode 3: Services and Dependency Injection

Introduces services and dependency injection as the backbone of logic reuse and modular design, as part of building a full Angular app.

03

Angular 16 Tutorial: Dependency Injection and Services

Explains what dependency injection is in Angular and how it relates to services, including how to create and use them.

04

Angular Dependency Injection: Explained in Easy Words

A plain-language explanation of Angular DI and how the injector lets you share services across components, other services, and directives.