Reputation: 21
I was trying to use my services
classes in components
, I did not get any compilation error, but got below error in browser console
ng:///CoreModule/LayoutComponent.ngfactory.js:418 ERROR Error: StaticInjectorError(AppModule)[ConnectionBackend]:
StaticInjectorError(Platform: core)[ConnectionBackend]: NullInjectorError: No provider for ConnectionBackend!
Upvotes: 2
Views: 598
Reputation: 4145
Import the HttpModule in your module. The HttpModule registers providers for all its services.
import {HttpModule} from '@angular/http';
@NgModule({
imports: [HttpModule],
declarations: [
// Your components
],
providers: [
// your services
],
bootstrap: [AppComponent]
})
Upvotes: 1
Reputation: 3688
You need to provide service if you want to use it.to add service in app.module.ts
@NgModule({
imports: [],
declarations: [],
providers: [ConnectionBackend], <- add here your service
bootstrap: [AppComponent]
})
Upvotes: 1