With the new angular 2 DI we can do this:
import HeroService from './HeroService'; bootstrap(AppComponent, [provide(HeroService,{useClass:HeroService})]);
Is there a way to code the interface so we can do this?
// typescript does not compile interfaces to plain js, we can use this in the provide function? interface SomeInterface { name: string } class HeroService implements SomeInterface {} bootstrap(AppComponent, [provide(SomeInterface,{ useClass: HeroService })]); // component class myComponent { constructor(hero: SomeInterface) {} }
source share