Problem with HttpClientModule Coexisting with HttpModule?

38 views
Skip to first unread message

Harry Whitehouse

unread,
Mar 5, 2019, 2:57:44 AM3/5/19
to Angular and AngularJS discussion
I've migrated a fairly large Angular 2 app to Angular 7.  The app makes use of Http but I'd like to begin using HttpClientModule/HttpClient.  My understanding is that I need to import the former in app.module.ts (see below for a code snippet)

Screen Shot 2019-03-04 at 11.34.00 PM.png

However, when I add this import the application crashes at startup (see above).  I'm only guessing that there is some sort of conflict between HttpModule and HttpClientModule.   I've successfully used HttpClientModule in a small test application, but in my larger legacy app, I can't seem to get anywhere.

Here's a snippet from my app.module.ts...


other imports....
import { HttpClientModule } from '@angular/common/http';

const routes: Routes = [
];

@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule, 
    HttpClientModule,  // causes crash at startup  
    JsonpModule,
    LandingModule,
    LoginRoutingModule,
    AppRoutingModule,
    RouterModule.forRoot(routes, { useHash: false }),
    NgxWebstorageModule.forRoot()
  ],
  providers: [
      AppConfig,
     more.........

Has anyone seen this behavior before? The error seems to point to a line in the system.js file but I can't decipher what the problem is:

Screen Shot 2019-03-04 at 11.54.56 PM.png



TIA

Harry


Sander Elias

unread,
Mar 5, 2019, 12:47:53 PM3/5/19
to Angular and AngularJS discussion
Hi Harry,

Have a look at this. Select your old, and the current version, There is a lot of detail on the things that changed.

Switch from HttpModule and the Http service to HttpClientModule and the HttpClientservice. HttpClient simplifies the default ergonomics (You don't need to map to json anymore) and now supports typed return values and interceptors. Read more on angular.io

That's about it on HTTP tho. I can't remember that I had any issues with moving to httpClient. However, I don't think you can/should load both of the modules. 

Regards
Sander
Reply all
Reply to author
Forward
0 new messages