gpt4 book ai didi

node.js - 从 Angular 4 升级到 5 : "NodeInvocationException: No provider for PlatformRef!"

转载 作者:太空狗 更新时间:2023-10-29 17:41:37 24 4
gpt4 key购买 nike

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

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

}

如果我降级回 Angular 4,该应用程序可以正常运行,我的想法中是否有任何地方做错了?

最佳答案

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

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

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

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

关于node.js - 从 Angular 4 升级到 5 : "NodeInvocationException: No provider for PlatformRef!",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47269890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com