[英]Using HttpModule (deprecated) with Angular 9
I recently updated from Angular 4 to 9. I did the following:我最近从 Angular 4 更新到 9。我做了以下事情:
rxjs
(added pipes where necessary, removed concat)rxjs
(在必要时添加了管道,删除了连接)HttpModule
(deprecated) to eliminate errors relating to 'cannot find HTTP' errors and get my project back on trackHttpModule
(已弃用)以消除与“找不到 HTTP”错误相关的错误,并使我的项目重回正轨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.我现在处于运行
ng build / ng serve
不会引发任何错误的地步,并且我能够访问本地主机并获取我的登录页面。 However, using my old login form does not work.但是,使用我的旧登录表单不起作用。 I keep getting a
CORS
error, though I have the following headers set in express
:我不断收到
CORS
错误,尽管我在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:我的问题是:
HTTP module
as I am trying to do?HTTP module
运行 angular 9 应用程序? If anyone has had success with it, were there any configuration changes / was it plug and play?HTTP module
rather than updating to httpClient? HTTP module
而不是更新到 httpClient 有关?httpClientModule
, is there a tool/utility that can be used to make this update easier?httpClientModule
,是否有可用于简化此更新的工具/实用程序? It is not so easy to upgrade 5 major versions at one shot.一口气升级 5 个主要版本并非易事。 You should better follow the updated guide
您最好遵循更新的指南
As for the HttpModule
, it is deprecated and removed after v7.至于
HttpModule
,它在 v7 之后已被弃用并删除。 It is much easier to upgrade to new HttpClientModule
than trying to make something removed working.升级到新的
HttpClientModule
比尝试使删除的内容正常工作要容易得多。
For people who are coming across this, here was how I ended up resolving my upgrade problems:对于遇到此问题的人,这是我最终解决升级问题的方法:
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.我知道这个问题被否决了——我不知道为什么,特别是因为它有超过 1,000 次观看。 Hopefully my answer helps anyone else struggling with this issue.
希望我的回答能帮助其他在这个问题上苦苦挣扎的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.