Skip to main content

What does "inversion of control" (IoC) mean?

Inversion of Control (IoC) is a principle where you do not control the creation and lifetime of objects, the framework does it for you.

In simple terms:

Normally you write:

ts
const service = new UserService();
  • that is, you decide yourself when and how to create the dependency.

With IoC you simply say:

ts
constructor(private userService: UserService) {}
  • and Angular itself creates and supplies UserService when it is needed.

Why this is needed:

  • Components do not depend on specific implementations.
  • The code becomes more flexible: one dependency can easily be replaced with another.
  • Testing is simpler, a fake dependency can be substituted.

Summary: Inversion of control is when control over creating objects is handed over to the framework. Angular does this through its Dependency Injection (DI) mechanism.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.