angular - 在角度 10 中创建对象的对象时出错
问题描述
export class School {
constructor(
public name: string,
public address: Address,
public district: string,
public contactNumber: string,
public gradeRange: string,
public currentYear: number,
public trialAcct: boolean,
public customerInfo: CustomerInfo,
public composing: boolean,
public createdAt: number,
){}
export class Address{
streetAddress1: string;
streetAddress2:string;
city: string;
state: string;
postalCode: string;
}
export class CustomerInfo{
public customerID: string;
public paymentID: string;
public subscriptionID: string;
public maskedPayment: string;
public firstName: string;
public lastName: string;
}
那是我为数据定义的模型,当使用我从 api 获得的数据创建此类的对象时,它没有提供给我的地址。但在数据地址中是提供的。这就是我创建这个对象的方式,
getSchool(): School {
return new School(this.schooldata);
}
this.schooldata 中包含数据。
我不知道我应该在哪里得到错误
解决方案
最好使用接口并传递它。
export interface objProp{
name: string,
address: Address,
district: string,
contactNumber: string,
gradeRange: string,
currentYear: number,
trialAcct: boolean,
customerInfo: CustomerInfo,
composing: boolean,
createdAt: number,
}
推荐阅读
- r - 如何通过 RDatastream::ds 在 R 中发出 Thomson Reuters 数据流请求?'user' 参数的可能错误规范
- c - Dart RawSockets 有什么用?
- io - 具有历史支持的 OCaml readline
- c# - 在 WPF 中执行一个函数直到 5 分钟
- json - 使用来自本地 json 文件的 html 中的数据 - typescript, angular 7
- css - 通过 js 悬停时显示工具提示,但在 css 中不显示
- python - TypeError:字符串索引必须是 Django 中的整数
- laravel - 获取关系模型数据
- c# - 如何使用我构建的应用程序从另一台计算机连接到 SQL Server 数据库
- sql - 我想使用“触发器”根据职业提供信息