这个问题是给ts 对象赋值的时候出现的
先说明结果: 需要给声明对象初始化
错误由来->
对象
export 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文件
...省略...
order:OrderInterface;
...省略....
this.order.carPrice = this.inputCarPrice;
this.order.carImg = this.Photo;
...省略....
报错
Cannot set property ‘display’ of undefined
这个时候问题出在 ts 中没有无参构造 所以需要在声明这个"对象"的时候进行初始化
某.ts文件
...省略...
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;
...省略....