[英]Angular 5 moment-range - typescript
Hi I am porting an application from Angular 1 to Angular 5 (Ionic 1 to Ionic 3). 嗨,我正在将应用程序从Angular 1移植到Angular 5(将离子1移植到离子3)。
In my Ionic 1 application I am using moment and moment-range 在我的Ionic 1应用程序中,我使用的是瞬间和瞬间范围
var range = moment.range(new Date(2018, 0, 1), new Date(2018, 11, 30));
range.by('days', function (day) {
// process each day
});
I am trying to get this working with typescript. 我正在尝试使用打字稿。 I am using: 我在用:
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/moment-range https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/moment-range
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/moment-range/moment-range-tests.ts https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/moment-range/moment-range-tests.ts
I have the following code from the test code provided by the above link: 我有上面链接提供的测试代码中的以下代码:
const range: momentRange.DateRange = new momentRange.DateRange(new Date(2018, 0, 11), new Date(2018, 11, 30));
const it0: Iterable<moment.Moment> = range.by('days');
At this point, I am not sure how to iterate over the returned range.by() values? 此时,我不确定如何对返回的range.by()值进行迭代?
You can use a for...of
loop on the resulting Iterable
object. 您可以在生成的Iterable
对象上使用for...of
循环。 Something like: 就像是:
const range: momentRange.DateRange = new momentRange.DateRange(new Date(2018, 0, 11), new Date(2018, 11, 30));
const it0: Iterable<moment.Moment> = range.by('days');
for (const day of it0) {
// do something with each day
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.