这个问题是给ts 对象赋值的时候出现的
先说明结果: 需要给声明对象初始化
错误由来->
对象
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17export interface OrderInterface{ orderId?: string; userId?: string; userName?:string; carModelName?: string; orderTime?: string; orderState?: string; model?: string; outwardWheel?: string; outwardColor?:string; interior?: string; features?: string; carImg?:string; carPrice?:string; }
某.ts文件
复制代码
1
2
3
4
5
6
7...省略... order:OrderInterface; ...省略.... this.order.carPrice = this.inputCarPrice; this.order.carImg = this.Photo; ...省略....
报错
Cannot set property ‘display’ of undefined
这个时候问题出在 ts 中没有无参构造 所以需要在声明这个"对象"的时候进行初始化
某.ts文件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21...省略... order:OrderInterface={ orderId:"", userId: "", userName: "", carModelName: "", orderTime: "", orderState: "", model: "", outwardWheel: "", outwardColor: "", interior: "", features: "", carImg: "", carPrice: "", }; ...省略.... this.order.carPrice = this.inputCarPrice; this.order.carImg = this.Photo; ...省略....
最后
以上就是殷勤裙子最近收集整理的关于[TypeScript 报错] Cannot set property ‘XXXXXXXX‘ of undefined的全部内容,更多相关[TypeScript内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复