Hour display hourSegments angular-calendar

2019-08-22 10:16发布

In my calendar I need to display the time of day and week as follows: 09:00, 09:15, 09:20.

I upgraded the package to the latest

angular-calendar version
0.26.1

and now the code below is giving error and I can no longer display the time as before.

module.ts:

class CustomDateFormatter extends CalendarNativeDateFormatter {
    public dayViewHour({ date, locale }: DateFormatterParams): string {
        return new Intl.DateTimeFormat('ca', {
            hour: 'numeric',
            minute: 'numeric'
        }).format(date);
    }
}
    // It does not work any more this way and error occurs ...
    CalendarModule.forRoot({
        dateFormatter: {
            provide: CalendarDateFormatter,
            useClass: CustomDateFormatter
        }
    }),

component.scss:

.cal-day-view .cal-hour-segment.cal-after-hour-start .cal-time {
    display: block;
  }

I looked in the documentation I searched elsewhere but could not find what I need ...

1条回答
戒情不戒烟
2楼-- · 2019-08-22 11:02

I've found the answer by thoroughly docs reading ("angular-calendar": "^0.27.14"). https://mattlewis92.github.io/angular-calendar/docs/modules/CalendarModule.html Signature of forRoot is forRoot(dateAdapter: Provider, config: CalendarModuleConfig)

So this code worked for me (with styling you mentioned above) and every hour segment has it's time.

    CalendarModule.forRoot({
      provide: DateAdapter,
      useFactory: adapterFactory
    }, {
      dateFormatter: {
        provide: CalendarDateFormatter,
        useClass: CustomDateFormatter
      }
    })
查看更多
登录 后发表回答