I have a strange error. Usually (I did my googling), in this case of errors Angular specifies in square brackets which exactly module/service/provider/etc caused the problem
I was having the same problem using my class SharedModule.
export class SharedModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: SharedModule,
providers: [MyService]
}
}
}
Then I changed it putting directly in the app.modules this way
@NgModule({declarations: [
AppComponent,
NaviComponent],imports: [BrowserModule,RouterModule.forRoot(ROUTES),providers: [MoviesService],bootstrap: [MyService] })
Obs: I'm using "@angular/core": "^6.0.2".
I hope its help you.
HttpClientModule needs to be in the imports array, and remove it from providers. That section is for you to tell Angular which services the module has (written by you and not imported from a library).
If we need to move from one component to another service then we have to define that service into app.module providers array.
I had the same error and I solved it by importing HttpModule
in app.module.ts
import { HttpModule } from '@angular/http';
and then in the imports[]
array:
HttpModule
Faced the same error. In my case , what i did wrong was that i injected the service(named DataService in my case) inside the constructor within the Component but I simply forgot to import it within the component.
constructor(private dataService:DataService ) {
console.log("constructor called");
}
I missed the below import code.
import { DataService } from '../../services/data.service';
In my case, the error was in using angular2-notifications 0.9.8
instead of 0.9.7