Angular 5 升级至Angular 7

栏目: JavaScript · 发布时间: 7年前

内容简介:本文内容“升级前-升级”适用于想从Angular 5升级至Angular 6的小伙伴;本文内容“升级后”适用于想从Angular 6升级至Angular 7的小伙伴;

根据升级建议,应该先从Angular 5升级至Angular 6,再从Angular 6升级至Angular 7。

本文内容“升级前-升级”适用于想从Angular 5升级至Angular 6的小伙伴;

本文内容“升级后”适用于想从Angular 6升级至Angular 7的小伙伴;

ng --version 可查看当前版本

升级前

1.HttpModule和Http Service 切换到 HttpClientModule和HttpClient Service

如果项目中有用到HttpModule和Http Service,把它们切换到HttpClientModule和HttpClient Service。

HttpClient有几个特性:

  • 不需要调用.json()来映射返回的数据到json格式,默认就是json格式
  • 支持拦截器

具体可以参考:HttpClient

2.如果有从@ angular / core导入任何动画服务或工具,则应从@ angular / animations导入它们

3.ngOutletContext替换为ngTemplateOutletContext

4.CollectionChangeRecord替换为IterableChangeRecord

升级

1.确保使用的是Node 8或更高版本

2.升级Angular CLI(全局和本地)

npm install -g @angular/cli

npm install @angular/cli

ng update @angular/cli

可在每行后面加@你想要的版本号,例如: npm install -g @angular/cli@6.0.0 ,以升级至Angular6。

3.迁移配置到当前版本的angular.json

ng update @angular/cli --migrate-only --from=1

ps:Angular5以下的配置文件名是angular-cli.json

4.升级Angular框架包到v6,以及升级RxJS和TypeScript。

ng update @angular/core

5.使用 ng update 查看更新情况

如果仍有需要更新的内容,会显示当前版本号和最新版本号的对比。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Introduction to Computation and Programming Using Python

Introduction to Computation and Programming Using Python

John V. Guttag / The MIT Press / 2013-7 / USD 25.00

This book introduces students with little or no prior programming experience to the art of computational problem solving using Python and various Python libraries, including PyLab. It provides student......一起来看看 《Introduction to Computation and Programming Using Python》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具