json数组第一个得到第二个值

时间:2017-02-21 07:23:53

标签: json angular

在Angular2中,我有一个返回Customer

的JSON

这是我的客户类:

export class Customer {
  customerNo: string;
  tckn: string;
  vkn: string;
  customerType: string;
  address: Address[];
  phone: Phone[];
}

这是我的地址类:

export class Address {
    addressType: string;
    tradeName: string;
    taxOfficeName: string;
    taxNo: string;
    addressName: string;
    addressString: string;
    building: string;
    floor: string;
    apartment: string;
    city: string;
    county: string;
    zipCode: string;
    addressDirection: string;
    department: string;
    indx:string;
}

这是我的customer.service.ts中的json;

getCustomerInfo(): any {
  return [{
    customerNo: '4767584',
    tckn: '968796',
    customerType: '1',
    address: [{
        addressName: '1.address',
        addressType: '1',
        city: '34',
        taxNo: '111'
      },
      {
        addressName: '2.address',
        addressType: '2',
        city: '6',
        apartment: 'test aprt'
      }
    ]
  }];
}

我将json附加到customer.component.ts

中的模型中
this.model = this._customerService.getCustomerInfo()[0] as Customer;

现在我记录this._customerService.getCustomerInfo()[0] as Customer; 我看到json还可以。

现在,记录this.model第一个地址获取第二个地址的值

你知道为什么会这样吗?

0 个答案:

没有答案