昨天我部署了一个angular2项目,偶然发现一个奇怪的行为。
当我在生产模式下编译项目时,函数的结果会发生变化(与dev相比)。
我检查了来自api的数据及其相同的数据。
丑陋的人还是其他东西弄乱了我的代码?或者有人可以解释一下我在“ --prod
”命令中添加“ ng build
”时会发生什么情况?
功能:
generateData(data: Call[]): void {
let result: CallHelper[] = [];
let counter: number = 0;
this.timeSeries = ['x'];
this.chartData = ['Calls'];
data.forEach((c) => {
result.push({ date: c.start_date, value: 1 } as CallHelper);
result.push({ date: c.end_date, value: -1 } as CallHelper);
});
result = result.sort((a, b) => {
return moment(a.date, 'YYYY-MM-DD HH:mm:ss').diff(moment(b.date, 'YYYY-MM-DD HH:mm:ss'));
});
let lastDate: string = "";
result.forEach((d) => {
counter = counter + d.value;
if (lastDate == '' || d.date != lastDate) {
this.chartData.push(counter);
this.timeSeries.push(moment(d.date, 'YYYY-MM-DD HH:mm:SS').format('YYYY-MM-DDTHH:mm:SS'))
}
else {
this.chartData[this.chartData.length - 1] = this.chartData[this.chartData.length - 1] + d.value;
}
lastDate = d.date;
})
console.log(this.timeSeries);
console.log(this.chartData);
}
输出比较:
对来自api的输入数据进行采样:
[
{
"id":751000375,
"start_date":"2019-01-19 08:05:42.0",
"end_date":"2019-01-19 08:08:54.0",
"wait_seconds":28,
"connect_seconds":164,
"afterwork_seconds":56,
"total_seconds":220,
"incoming_number":"*********",
"connected":true,
"in_advanced_time":false
},
{
"id":751000391,
"start_date":"2019-01-19 08:16:59.0",
"end_date":"2019-01-19 08:17:28.0",
"wait_seconds":5,
"connect_seconds":24,
"afterwork_seconds":116,
"total_seconds":140,
"incoming_number":"*******",
"connected":true,
"in_advanced_time":false
}
]
答案 0 :(得分:0)
已解决。我得到了将这一行if (lastDate == '' || d.date != lastDate)
更改为这一行if (!lastDate || !lastDate.isSame(moment(d.date,'YYYY-MM-DD HH:mm:SS')))
的提示,现在它可以工作了。它没有解释为什么没有生产标志就可以工作,但是可以工作。