在角度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中包含数据。

我不知道应该从哪里得到错误

解决方法

您的构造函数接受很多参数,而不是对象

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,){}

调用构造函数的有效方法应该是

new School(name,address,district,contactNumber,etc....);
,

最好使用接口并将其传递。

fun truncate(n,p) = do {
    var power = 10 pow p
    ---
    if (n>0) floor(n * power)/power
    else ceil(n * power)/power
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...