2

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!

Amit Chigadani
  • 28,482
  • 13
  • 80
  • 98
  • Possible duplicate of [Angular 2 : No provider for ConnectionBackend](https://stackoverflow.com/questions/40098413/angular-2-no-provider-for-connectionbackend) – Amit Chigadani Sep 05 '18 at 09:46

2 Answers2

1

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]
})
Aniket Avhad
  • 4,025
  • 2
  • 23
  • 29
1

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]
})
Nenad Radak
  • 3,550
  • 2
  • 27
  • 36