简体   繁体   中英

Using HttpModule (deprecated) with Angular 9

I recently updated from Angular 4 to 9. I did the following:

  1. Created new Angular 9 project, copied all code into angular 9 project
  2. Updated rxjs (added pipes where necessary, removed concat)
  3. Fixed easy to fix warnings (unused modules variables etc)
  4. Installed HttpModule (deprecated) to eliminate errors relating to 'cannot find HTTP' errors and get my project back on track

I am now at the point where running ng build / ng serve does not throw any errors, and I am able to visit local host and get my landing page. However, using my old login form does not work. I keep getting a CORS error, though I have the following headers set in express :

app.use(function(req, res, next) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS');
  next();
});

Relevant Package Details: "@angular/core": "~9.1.4" <-- all angular components are at this point, "@angular/common": "~9.1.4", "@angular/http": "^7.2.16", "express": "^4.17.1"

My questions are:

  1. Is it possible to run an angular 9 app with the HTTP module as I am trying to do? If anyone has had success with it, were there any configuration changes / was it plug and play?
  2. Is it possible the CORS error could be related to using HTTP module rather than updating to httpClient?
  3. If I have to update to httpClientModule , is there a tool/utility that can be used to make this update easier?

It is not so easy to upgrade 5 major versions at one shot. You should better follow the updated guide

As for the HttpModule , it is deprecated and removed after v7. It is much easier to upgrade to new HttpClientModule than trying to make something removed working.

For people who are coming across this, here was how I ended up resolving my upgrade problems:

  1. I created an new project with angular CLI.
  2. I moved all my code into the new project and then went through and fixed any exceptions one at a time.

I wish there was an easier way to do it because this was a time consuming process. However, in the end it worked out and I was able to upgrade the entire project.

I know this question has been downvoted - I'm not sure why, especially since it has had over 1,000 views. Hopefully my answer helps anyone else struggling with this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM