2. Dependency Injection - ShakthiSampath/Learning-Angular.io GitHub Wiki

Dependency Injection

Introduction

  • What is Dependency Injection?
  • Dependency and Injection
  • Requirement of the pattern and intent - Decouple Objects
  • Inversion of control

Problems Solved using Dependency Injection

  • problems due to dependencies and they being reduced
  • testing easy

Code Snippet

Without DI
public engine: Engine;
public tires: Tires;
public description = 'No DI';

constructor() {
 this.engine = new Engine();
 this.tires = new Tires();
}
With DI
public description = 'DI';
constructor(public engine: Engine, public tires: Tires) { }