NetanelBasal
1/27/2017 - 2:20 PM

skipSelf.di.ts

class Dependency {}

class ChildDependency {
 constructor() {
   console.log("ChildDependency");
 }
}

class ParentDependency {
 constructor() {
   console.log("ParentDependency");
 }
}

@Component({
  selector: 'cmp',
  template: `
    cmp
  `,
  providers: [{ provide: Dependency, useClass: ChildDependency }]
})
export class DIComponent {
  constructor(@SkipSelf() public dependency: Dependency) {}
}

@Component({
  selector: 'my-app',
  template: `
    <cmp></cmp>
  `,
})
export class App {}

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ App,  DIComponent],
  providers: [{ provide: Dependency, useClass: ParentDependency }],
  bootstrap: [ App ]
})
export class AppModule {}