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.
Angular DI
│ constructor(private marks)
▼
MarksService (root)Exam tip
constructor inject + providedIn. NullInjectorError meaning.