域模型角度2

时间:2016-08-02 10:39:07

标签: json class angular model

我收到了一个带有这种形式的json对象:

[{ 
"id": 1,
"url": "url 1",
"name": "Luke Skywalker",
"height": 172,"weight": 77,
"Cars":["car1","car2"]
}]

我创建了一个数据模型

**Person.ts**
id: number;
url: string;
name: string;
height: number;
weight: number;
cars:Car[];

Car.ts:
id_car:number;
name_car:string;
info_car:string;

但不接受在person.ts中添加此行(cars:Car [])

那我该怎么办?

1 个答案:

答案 0 :(得分:0)

尝试使用此: 的 Person.ts

    id: number;
    url: string;
    name: string;
    height: number;
    weight: number;
    cars: {
     type: [{
        type: String,
            }],

    }