I am trying to implement a sample project using Angular 2. Here I am divided different sub modules and imported in my app.module.ts. And service also I am importing from service section. And defines routes to different components. When I am running, I am getting the following error message:
ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[UserrequestService -> String]:
The entire error stack is as follows:
ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[UserrequestService -> String]:
StaticInjectorError(Platform: core)[UserrequestService -> String]:
NullInjectorError: No provider for String!
Error: StaticInjectorError(AppModule)[UserrequestService -> String]:
StaticInjectorError(Platform: core)[UserrequestService -> String]:
NullInjectorError: No provider for String!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:8896)
at resolveToken (core.js:9141)
at tryResolveToken (core.js:9085)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:8982)
at resolveToken (core.js:9141)
at tryResolveToken (core.js:9085)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:8982)
at resolveNgModuleDep (core.js:21218)
at _createClass (core.js:21265)
at _createProviderInstance (core.js:21235)
at resolvePromise (zone.js:831)
at resolvePromise (zone.js:788)
at zone.js:892
I readed about it is the problem of imporing old version of HttpModule from angular/core. And I tried to import HttpClientModule from angular/common/http. But no change in error. And HttpModule from angular/core also added. But also no change, error is still like same.
Here I am adding my app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { FlexLayoutModule } from '@angular/flex-layout';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
AppComponent,
FilterPipe
],
imports: [
HttpClientModule,
BrowserModule,
BrowserAnimationsModule,
FormsModule,
ReactiveFormsModule,
ApprouterModule,
MaterialModule,
FlexLayoutModule,
],
providers: [HttpClientModule],
bootstrap: [AppComponent]
})
export class AppModule { }
Where have I gone wrong in my code?