从Angular 4升级到5:"NodeInvocationException:没有PlatformRef的提供者!"

mra*_*api 4 node.js npm asp.net-core angular angular5

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

NodeInvocationException:没有PlatformRef的提供者!错误:没有PlatformRef的提供程序!at injectionError(e:\ myapp\ClientApp\dist\vendor.js:12066:90)

该应用程序还使用webpackASP.NET Core.

我安装了node v9.1,和typescript 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 
Run Code Online (Sandbox Code Playgroud)

然后,运行以下内容:

 npm install --save-dev @ngtools/webpack@latest
Run Code Online (Sandbox Code Playgroud)

我也用过HttpClient而不是Http:

import { HttpClient } from '@angular/common/http'; 
.....
 getThings() {
        return this.http.get('/api/things');

  }
Run Code Online (Sandbox Code Playgroud)

如果我降级回Angular 4,该应用程序工作正常,我的思路中是否有任何错误的做法?

mra*_*api 18

我找到了解决方案:我使用了这个 Angular 5 Asp Core模板

我已经更新了最新的angular 5版本的dependecies: 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
Run Code Online (Sandbox Code Playgroud)

我已经重新编译 webpack --config webpack.config.vendor.js(必须的WebPack全球的装机量: npm install -g webpack@2.5.1)

我用我的项目文件Manully更改了ClientApp/ASP文件app.module:

import { HttpModule } from '@angular/http';
Run Code Online (Sandbox Code Playgroud)

import { HttpClientModule } from '@angular/common/http';
Run Code Online (Sandbox Code Playgroud)

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

import { HttpClient } from '@angular/common/http'; 
Run Code Online (Sandbox Code Playgroud)

  • `webpack --config webpack.config.vendor.js`帮助我克服了这个问题. (5认同)