从 Angular 4 升级到 5:“NodeInvocationException: No provider for PlatformRef!" [英] Upgrade from Angular 4 to 5: "NodeInvocationException: No provider for PlatformRef!"

查看:25
本文介绍了从 Angular 4 升级到 5:“NodeInvocationException: No provider for PlatformRef!"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将应用程序从 Angular 4.2 升级到 5,但出现此错误:处理请求时发生未处理的异常,更具体地说:

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 的提供者!注射错误(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)

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

The app also uses webpack and ASP.NET Core.

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

I have installed node v9.1, and 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:

I've also used HttpClient instead of 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@最新@angular/http@latest @angular/platform-b​​rowser@latest @angular/platform-b​​rowser-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: No provider for PlatformRef!"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆