Check out these sample constructors I found in the Angular 2 documentation:
export class AppComponent implements OnInit {
title = 'Tour of heroes';
heroes: Hero[];
selectedHero: Hero;
constructor(private heroService: HeroService) { }
getHeroes() {
this.HeroService.getHeroes().then(heroes => this.heroes = heroes);
}
}
as well as...
class Car {
constructor(engine, tires, doors){
this.engine = engine;
this.tires = tires;
this.doors = doors;
}
}
I'm curious about the purpose and timing for using a constructor()
in Angular 2 / Typescript (I have seen examples in the official docs related to Dependency Injection and Services).