Angular: getting started

Lesson 03 · 11 min

Services and DI

HTTP and shared state don't live in every component. They go into a service.

11 minLesson 3 of 8Practice includedAsk AI on any point

A service is an ordinary class with @Injectable({ providedIn: "root" }). Angular creates one instance and puts it wherever you ask for it in a constructor. A component doesn't do new UserApi(): it writes constructor(private api: UserApi) and gets a ready object.

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.