angular7升级到angular8

最近换了项目组,技术栈也更换了(原来是Vue,现在是angular)。正好赶上版本升级,于是自己尝试升级,顺便记录了过程中遇到的问题,希望可以帮到需要升级的朋友。

  1. 先使用ng update 查看我们这个项目需要升级的依赖
    在这里插入图片描述
  2. 依次升级对应的依赖(根据上图中 Command to update的提示一次升级)
 ng update @angular/cli
  1. 升级后踩过的坑(问题下面的解决方案,只是写了一个示例)
    可以通过 ng lint指令,查看需要修改的文件列表,根据提示一一修改。
    也可以先通过ng lint --fix指令,先自动修复。然后再看需要手动修复的错误。
    (1) ViewChildContentChild 用法发生了变化
Before:
		@ViewChild('foo') foo: ElementRef;
After:
		@ViewChild('foo', {static: true}) foo: ElementRef;

(2) Boolean ===》 boolean
问题:Type boolean trivially inferred from a boolean literal, remove type annotation
@output showAllTab :boolean = false; 改为 @output showAllTab = false;
(3) 问题:Consecutive blank lines are forbidden 禁止连续空行
(4) 问题:Don't use 'String' as a type. Avoid using theStringtype. Did you meanstring?
name: String; 改成 name: string;
(5) 问题:Don't use 'Number' as a type. Avoid using theNumbertype. Did you meannumber?
categoryId: Number; 改为 categoryId: number;
(6) 问题:Don't use 'Object' as a type. Avoid using theObjecttype. Did you meanobject?
totalBillList: Object = new TotalBillModel(); 改为 totalBillList: object = new TotalBillModel();
(7) 问题:Unnecessarily quoted property 'username' found.
‘username’: username 改为 username: username
(8) 问题: Spaces before function parens are disallowed

formatter: function (value) {
	return '$' + value;
}

改为

formatter: value => {
	return '$' + value;
}

(9) 问题:Type number trivially inferred from a number literal, remove type annotation
有初始值的话 不需要定义类型
selectType: number = 0; 改为 selectType= 0;
(10) 问题:Multiple variable declarations in the same statement are forbidden
多元变量禁止在同一条语句中声明
const input = control.value, isValid = input < min;
改为

 const input = control.value;
 const isValid = input < min;

(11) 问题: statements are not aligned 语句未对齐
(12) 问题:file should end with a newline。 文件应以换行符结尾

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值