HTML 模板数组变量中的角度 10 与类型声明不匹配



我使用一个全局变量和类型定义为:

global.ts

export type ReservationCurrentPC = Array<{StartDateTime: string, EndDateTime: string, Who: string}>;
export class GlobalVariables {
public static ReservationsCurrentPC: ReservationCurrentPC = [];
}

然后导入到component .ts

import { GlobalVariables , ReservationCurrentPC } from '../GlobalVariables';

然后在组件上做了一个getter。

get GetReservationsMyPC(): ReservationCurrentPC { return GlobalVariables.ReservationsCurrentPC; };

则执行单次push:

case 'RSV':
// stemp[i].Param1 = PCNameID.
// stemp[i].Param2 = StartDate.
// stemp[i].Param3 = EndDate.
// stemp[i].Param4 = ReserveByAccountName.
GlobalVariables.ReservationsCurrentPC.push (stemp[i].Param2, stemp[i].Param3, stemp[i].Param4);

,然后尝试在HTML模板中使用它。

<div *ngFor="let b of GetReservationsMyPC">
<li>
Desde [{{b.StartDateTime}}] hasta [{{b.EndDateTime}}] reservado para: {{b.Who}}
</li>
<button (click)="RemReserve(b.StartDateTime)">Remover esta reserva</button>          
</div>

问题是,html循环3次变量'b',它不识别类型结构,就像每个项目3个字段,就像b. startdatetime, b. enddatetime, b.谁返回什么都没有,只有打印'b'变量它会得到3个字符串,就好像它是一个单一的普通数组。

如何在html模板中正确处理结构化变量?我看见几个例子,但使用地方的成分变量,工作,但是我需要使用这个全局变量,因为它是需要填补从另一个组件(处理一个用户点击地图视图,和对象的点击地图触发一些事件,而这正是从API请求信息点击对象,以及响应它返回的数据推动),所以,它必须是一个全局变量,因为它是处理几个组件。

fixed:

GlobalVariables.ReservationsCurrentPC.push ({StartDateTime: stemp[i].Param2, EndDateTime: stemp[i].Param3, Who: stemp[i].Param4 });

对我来说真是一次冒险!

最新更新