I read this article and watched these videos about Dependency Injection in Angular 2:
and quite understand about DI in Angular. But I'm confused on how to use it right.
My question is when to use Type Definition(1) like this:
import { Component } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'example-component',
template: '<div>I am a component</div>'
})
class ExampleComponent {
constructor(private http: Http) {}
}
And when to use Injector(2) like this:
import { Injector, provide } from 'angular2/core'
var injector = Injector.resolveAndCreate(
[
provide(SomeObj, {useClass: SomeObj})
]);
The second one gets me confused as I'm not sure where it's supposed to go (Component, Service, or else?), how to consume it?