从Angular 4升级到5:"NodeInvocationException:PlatformRef没有提供者!" [英] Upgrade from Angular 4 to 5: "NodeInvocationException: No provider for PlatformRef!"
问题描述
我已将应用程序从Angular 4.2升级到5,但出现此错误:
unhandled exception occurred while processing the request
,更具体地说:
I've upgraded an app from Angular 4.2 to 5, but got this error:
unhandled exception occurred while processing the request
, more specifically:
NodeInvocationException:没有PlatformRef的提供程序!错误:否 PlatformRef的提供者!在injectionError时 (e:\ myapp \ ClientApp \ dist \ vendor.js:12066:90)
NodeInvocationException: No provider for PlatformRef! Error: No provider for PlatformRef! at injectionError (e:\myapp\ClientApp\dist\vendor.js:12066:90)
该应用程序还使用 webpack 和ASP.NET Core
.
我已经安装了node v9.1
和typescript 2.6.1
.
我还使用以下命令更新了package.json
:
I also have updated package.json
, with the command:
npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest
然后,运行以下命令:
npm install --save-dev @ngtools/webpack@latest
我还使用了HttpClient
而不是Http
:
import { HttpClient } from '@angular/common/http';
.....
getThings() {
return this.http.get('/api/things');
}
如果我将Angular 4降级,则该应用程序可以正常工作,是否有我做错的事情?
If I downgrade back Angular 4, the app works fine, is there anything in my line of thought that has been done incorrectly?
推荐答案
我找到了一个解决方案: 我已经使用过 Angular 5 Asp Core模板
I found a solving solution: I've used this Angular 5 Asp Core template
我已经将依存关系更新为最新的angular 5版本:npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest
I've updated dependecies to latest angular 5 version: npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest
npm install --save-dev @ngtools/webpack@latest
我已经重新编译webpack --config webpack.config.vendor.js
(必须全局安装webpack:npm install -g webpack@2.5.1
)
I've recompiled webpack --config webpack.config.vendor.js
(must have webpack installed globally: npm install -g webpack@2.5.1
)
我已经用项目文件替换了ClientApp/ASP文件
在app.module
中进行了手动更改:
I've replaced ClientApp/ASP files with my project files
Manully changed in app.module
:
import { HttpModule } from '@angular/http';
到
import { HttpClientModule } from '@angular/common/http';
服务文件中的
而不是Http
我已经使用了HttpClient
:
in services files instead of Http
I've used HttpClient
:
import { HttpClient } from '@angular/common/http';
这篇关于从Angular 4升级到5:"NodeInvocationException:PlatformRef没有提供者!"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!