简体   繁体   English

从Angular 6迁移到Angular 7

[英]migrating from Angular 6 to Angular 7

I have recently upgraded my Angular 4 app to Angular 6 and now want to upgrade to Angular 7. According to the below article , running command the following command shouldn't take more than 10 mins to upgrade. 我最近将Angular 4应用程序升级到了Angular 6,现在想升级到Angular7。根据下面的文章,运行命令以下命令的升级时间不会超过10分钟。

ng update @angular/cli @angular/core ng update @ angular / cli @ angular / core

https://blog.angular.io/version-7-of-angular-cli-prompts-virtual-scroll-drag-and-drop-and-more-c594e22e7b8c https://blog.angular.io/version-7-of-angular-cli-prompts-virtual-scroll-drag-and-drop-and-more-c594e22e7b8c

I dont see anything happening on the command prompt after running this command. 运行此命令后,在命令提示符下我什么都没看到。 No errors. 没有错误。 Could somebody tell me why this is happening 有人可以告诉我为什么会这样吗

I've updated 6 to 7 using: 我使用以下方法将6更新为7:

Angular dependencies 角度依赖

   npm install @angular/animations@latest @angular/common@latest @angular/compiler@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 --save

Angular dev dependencies Angular开发依赖

  npm install @angular-devkit/build-angular@latest @angular/compiler-cli@latest @angular/cli@latest @angular/language-service@latest --save-dev

Dependencies; 相关性; Core-js and Zone.js Core-js和Zone.js

npm install core-js@latest zone.js@latest --save

Dev dependencies; 开发依赖项; Types, codelyzer, karma tools, jasmine, protractor and tslint 类型,代码解析器,业力工具,茉莉花,量角器和tslint

npm install @types/jasmine@latest @types/node@latest codelyzer@latest karma@latest karma-chrome-launcher@latest karma-cli@latest karma-jasmine@latest karma-jasmine-html-reporter@latest jasmine-core@latest jasmine-spec-reporter@latest protractor@latest tslint@latest --save-dev

The new version 3+ of TypeScript 新版本的TypeScript 3+

npm install typescript@latest --save-dev

Latest version 6+ of RxJS RxJS的最新版本6+

npm install rxjs@latest rxjs-compat@latest --save

And: 和:

npm install rxjs-tslint@latest --save-dev

Latest version 4+ of Webpack 最新版本的Webpack 4+

npm install webpack@latest --save-dev

source 资源

here,you can find guide related to update from any version to angular 7 在这里,您可以找到与从任何版本更新到angular 7有关的指南

https://update.angular.io/ https://update.angular.io/

Or you can simply run a command into your CLI 或者您可以直接在CLI中运行命令

  ng update --all

ANGULAR 6.1 to 7 MIGRATION PROCEDURE 6.1至7的角度迁移程序

In order to upgrade properly from Angular 6.1 to angular 7, you have to follow the next steps: 为了从Angular 6.1正确升级到angular 7,您必须执行以下步骤:

WARNING: Please check if all your imported modules are compatible with angular 7, upgrade them if necessary. 警告:请检查所有导入的模块是否与angular 7兼容,如有必要,请升级它们。

Before upgrade to Angular 7: 升级到Angular 7之前:

  1. Change the HttpModule import to HttpClientModule (import {HttpClientModule} from '@angular/common/http';) 将HttpModule导入更改为HttpClientModule(从'@ angular / common / http'导入{HttpClientModule};)

  2. Change the Http imports (if you have any) to import {HttpClient} from '@angular/common/http'; 更改Http导入(如果有),以从'@ angular / common / http'导入{HttpClient};

Don´t forget to remove all JSON.parse(response), since you don´t need to do that anymore with HttpClient 不要忘了删除所有JSON.parse(response),因为您不再需要使用HttpClient来做到这一点。

  1. If you are using RXjs, you have to remove RXjs 6 old dependencies. 如果使用的是RXjs,则必须删除RXjs 6的旧依赖性。 No worries, you can do that running the following scripts: 不用担心,您可以运行以下脚本来做到这一点:

    npm install -g rxjs-tslint npm install -g rxjs-tslint

    rxjs-5-to-6-migrate -p src/tsconfig.app.json rxjs-5-to-6-migrate -p src / tsconfig.app.json

You may have to update typescript in order to migrate rxjs successfully: npm i -g typescript 为了成功迁移rxjs,可能必须更新打字稿:npm i -g打字稿

  1. Uninstall rxjs-compat module (npm uninstall rxjs-compat) 卸载rxjs-compat模块(npm卸载rxjs-compat)
  2. If you use the Angular Service worker, migrate any versionedFiles to the files array. 如果使用Angular Service工作器,请将所有versionedFiles迁移到files数组。

  3. Update angular cli to v7: 将angular cli更新到v7:

    ng update @angular/cli ng update @ angular / cli

  4. Update angular Core to v7: 将Angle Core更新到v7:

    ng update @angular/core ng更新@ angular / core

  5. Finally you have to upgrade Angular material: 最后,您必须升级Angular材质:

    ng update @angular/material ng更新@ angular / material

ng-update也不适合我-我通过使用npm-check更新所有软件包并整理出手动后遇到的一些错误来解决该问题。

If you are looking like me for just updating your project to the latest these is what works form me since Angular 6: 如果您像我一样只是将项目更新为最新版本,那么从Angular 6开始,这些就是我的工作方式:

Open the console on your project folder: If you type: ng update then you will get the below message: 打开项目文件夹上的控制台: If you type: ng update ,则会收到以下消息:

        We analyzed your package.json, there are some packages to update:

          Name                               Version                  Command to update
         --------------------------------------------------------------------------------
          @angular/cli                       7.0.7 -> 7.2.2           ng update @angular/cli
          @angular/core                      7.0.4 -> 7.2.1           ng update @angular/core

There might be additional packages that are outdated.
    Run "ng update --all" to try to update all at the same time.

So I usually go straight and do: 因此,我通常会直接去做:

ng update --all

Finally you can check your new version: 最后,您可以检查新版本:

 ng version 
Angular CLI: 7.2.2
Node: 8.12.0
OS: win32 x64
Angular: 7.2.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.2
@angular-devkit/build-angular     0.12.2
@angular-devkit/build-optimizer   0.12.2
@angular-devkit/build-webpack     0.12.2
@angular-devkit/core              7.2.2
@angular-devkit/schematics        7.2.2
@angular/cli                      7.2.2
@ngtools/webpack                  7.2.2
@schematics/angular               7.2.2
@schematics/update                0.12.2
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.28.4

You can use this: 您可以使用此:

https://update.angular.io https://update.angular.io

Select the version you're using and it will give you a step by step guide. 选择您正在使用的版本,它将为您提供逐步指南。

从update.angular.io打印

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM