什么可能是Angular 2打字稿中json对象List的返回类型?

时间:2016-06-16 05:33:30

标签: typescript angular

这里可能是getFiles()的返回类型(除了any之外)可能是什么特定的返回类型?

   @Injectable()
    export class NodeService {

        constructor(private http: Http) {}

        getFiles() {
            return this.http.get('./resources/data/cars-medium.json')
                        .map((res: any) => res.json().data);
        }
    }

cars-medium.json

{
    "data":[
        {"vin":"a1653d4d","brand":"VW","year":1998,"color":"White"},
        {"vin":"ddeb9b10","brand":"Mercedes","year":1985,"color":"Green"},
        {"vin":"d8ebe413","brand":"Jaguar","year":1979,"color":"Silver"},
        {"vin":"aab227b7","brand":"Audi","year":1970,"color":"Black"},
        {"vin":"631f7412","brand":"Volvo","year":1992,"color":"Red"},
        {"vin":"7d2d22b0","brand":"VW","year":1993,"color":"Maroon"}
           ]
}

1 个答案:

答案 0 :(得分:4)

getFiles():Observable<Object[]> {

如果你有像

这样的界面
interface Car {
  vin:string;
  brand: string;
  year:number;
  color:string;
}

您也可以使用

getFiles():Observable<Car[]> {