PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Angular · Theory

Dependency Injection

← All stacks

Theory

14/43

Dependency Injection

DI means Angular creates the object and passes it in the constructor. constructor(private marks: MarksService). You don’t call new. Providers tell Angular how to make it.

providedIn: 'root' → one singleton. providedIn a component → new instance for that component tree. Use root for MarksService. Use component provider only when you want isolation.

Trap: circular inject (A needs B needs A). Split a third helper. Another trap: forgetting to provide a non-root service and getting NullInjectorError.

Diagram
  Angular DI
     │ constructor(private marks)
     ▼
  MarksService (root)
Exam tip

constructor inject + providedIn. NullInjectorError meaning.

Example

import { Injectable } from "@angular/core";

@Injectable({ providedIn: "root" })
export class UserService {
  getName() {
    return "Asha";
  }
}

Dependency Injection — services hold shared logic; Angular DI injects them into components.

Short notes

  • DefAngular constructs and injects. No new.
  • Ruleroot singleton vs component-scoped.
  • TrapNullInjectorError / circular DI.

Questions

1

What is dependency injection in Angular?

2

What is NullInjectorError?

Previous← ServicesNextPipes →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.