4

When nesting a service into another service in Angular 2 no typescript errors are thrown. However, when the page with the top component is loaded, the following error is logged in the console: EXCEPTION: No provider for ConfigService! (AdminAreaComponent -> CoreService -> ConfigService)

What do I need to do to prevent this?

app.ts:

import {bootstrap} from 'angular2/platform/browser'
import {AdminAreaComponent} from './components/adminArea.component'
var adminArea = bootstrap(AdminAreaComponent);

adminArea.component.ts

import {Component} from 'angular2/core'
import {CoreService} from '../services/core.service'

@Component({
    selector: 'admin-area',
    templateUrl: 'partials/adminArea.html',
    providers: [CoreService]
})
export class AdminAreaComponent {
    constructor(private coreService: CoreService) {}
}

core.service.ts

import {Injectable} from 'angular2/core'
import {ConfigService} from './config.service'

@Injectable()
export class CoreService {
    constructor(private configService : ConfigService) { }
}

config.service.ts

import {Injectable} from 'angular2/core'

@Injectable()
export class ConfigService {
    constructor() { }
}
Saksham
  • 9,037
  • 7
  • 45
  • 73
sqwk
  • 2,649
  • 1
  • 28
  • 42

1 Answers1

3

Seems ConfigService is not listed with the providers in

bootstrap(AppComponent, [... CoreService, ConfigService])

or in the providers list of the component (if you want to limit the scope of the service) as mentioned by Eric.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567