October 2017
Intermediate to advanced
280 pages
6h 50m
English
Another way we can approach this is by taking advantage of the DI pattern. We're already familiar with it from AngularJS; let's demonstrate how we can refactor the preceding code using DI in the context of Angular:
class Engine {...}
class Transmission {...}
@Injectable()
class Car {
engine;
transmission;
constructor(engine: Engine, transmission: Transmission) {
this.engine = engine;
this.transmission = transmission;
}
}
All we did in the preceding snippet was adding the @Injectable class decorator on top of the definition of the Car class and providing type annotations for the parameters of its constructor.
Read now
Unlock full access