我的模特:
export class Customer
{
CustomerId :number
FirstName : string
LastName : string
Email : string
Phone : string
ConfirmPassword:string
Password : string
Address : string//**I want to define address as array.Because I got List of Address from Customer as shown in the image.**
}
来自客户API的地址数组。如何实现?
答案 0 :(得分:1)
应该是
customers : Customer[] = [];
编辑:
您需要按照以下步骤为Address设置一个类,
export class Customer
{
AddressId : string;
... etc
}
在您的Cusomter类中,
export class Customer
{
CustomerId :number
FirstName : string
LastName : string
Email : string
Phone : string
ConfirmPassword:string
Password : string
Address : Address[]
}
答案 1 :(得分:1)
答案 2 :(得分:1)
首先,您必须创建一个地址打字稿类,如下所示。
export class Address {
addressId: string;
customerId: string;
firstName: string;
lastName: string;
}
然后在 Customer 类中定义地址数组属性。
export class Customer {
customerId :number
firstName : string
lastName : string
email : string
phone : string
confirmPassword:string
password : string
address : Address[];
}
然后迭代客户及其地址。
<ul *ngFor="let customer of customers">
<li>
<div>
<strong>
{{customer?.firstName}}
{{customer?.lastName }}
</strong>
<span>-</span>
<div *ngFor="let adr of customer?.address">
{{ adr?.addressId + ', ' + adr?.customerId + ', ' + adr?.firstName}}
</div>
</div>
</li>
</ul>
答案 3 :(得分:0)
您必须定义以下内容:ToString
,然后在Customer类中,您必须将地址属性类型从字符串更改为Adress []