When working with Angular2 components, I know that to inject a dependency, you simply annotate an argument in the constructor, like how ThingService
is injected here. However, what I am wondering is how Angular actually knows what to inject at runtime. As far as I understand, this annotation is just for TypeScript and doesn't have any impact during runtime. So, what is the underlying mechanism that manages which providers are inserted into a component's constructor? If one were to build this system from scratch, how would it function? Is this related to a TypeScript concept that I may be missing?
@Component({
selector: 'app-thing',
templateUrl: './thing.component.html',
styleUrls: ['./thing.component.scss']
})
export class ThingComponent {
constructor(
private thingService: ThingService) {
}
}