从 Angular 4 升级到 5:"NodeInvocationException: No provider for PlatformRef!"

Upgrade from Angular 4 to 5: "NodeInvocationException: No provider for PlatformRef!"

我已将应用程序从 Angular 4.2 升级到 5,但出现此错误: unhandled exception occurred while processing the request,更具体地说:

NodeInvocationException: No provider for PlatformRef! Error: No provider for PlatformRef! at injectionError (e:\myapp\ClientApp\dist\vendor.js:12066:90)

该应用还使用 webpackASP.NET Core

我已经安装了node v9.1typescript 2.6.1

我也更新了 package.json,命令为:

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');

  }

如果我降级回Angular4,应用程序运行正常,我的思路有没有做错?

两个不同的东西,你可以试试:

1) 首先在 NgModule 的导入数组中导入 HttpClientModule。(如果您在组件中使用 HttpClient)

2)

注意:要升级您的应用程序:https://onlyforcoder.blogspot.in/2017/11/angular-5-upgrade-your-project-To-Angular5.html

我找到了解决方案: 我用过这个 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

npm install --save-dev @ngtools/webpack@latest

我重新编译了webpack --config webpack.config.vendor.js(必须全局安装webpack:npm install -g webpack@2.5.1

我用我的项目文件替换了 ClientApp/ASP 文件 在 app.module 中手动更改:

import { HttpModule } from '@angular/http';

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

在服务文件中而不是 Http 我使用 HttpClient:

import { HttpClient } from '@angular/common/http';