在地图函数中调用数组

时间:2019-01-19 06:58:15

标签: angular typescript

我已经初始化并声明了一个模型。我在地图函数中调用该模型的元素。在该模型中,我有两个字段和一个数组。当我在地图功能中传递模型时。我可以获取两个字段的值,但数组显示未定义。看来我在地图中的数组格式是错误的。谁能帮帮我。

abc.ts

export class ABC {
date: Date;
time: string;
ABC_Info: any[];

constructor(date: Date, time: string, ABC_Info: {
    item: string,
    quantity: number,
    a: number
} []) {
    this.date = date;
    this.time = time;
    this.ABC_Info = ABC_Info;
  }
}

abc.service

import { ABC} from './models/abc';

getABC(start ? : moment.Moment, end ? : moment.Moment): Observable < ABC[] > {
let params = new HttpParams();

if (start) {
    params = params.append('start', start.toISOString());
}

if (end) {
    params = params.append('end', end.toISOString());
}
return this.baseService.getParams('/api/abc/getAll', params)
    .pipe(
        map(res => res as Object[] || []),
        map(abc => abc.map(k => new ABC(
            new Date(k['date']), // I can get values for this, when I GET
            k['time'], //  I can get values for this, when I GET
            k['ABC_Info'] //I am getting undefined for this, when I GET
        )))
    )
 }

0 个答案:

没有答案