@pieninck/ionic2-calendar 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,1027 @@
1
+ # Ionic-Calendar directive
2
+
3
+ Ionic calendar directive
4
+ @pieninck/ionic2-calendar
5
+ [![version](https://img.shields.io/npm/v/%40pieninck%2Fionic2-calendar/latest.svg)](https://www.npmjs.com/package/@pieninck/ionic2-calendar)
6
+ ionic8-calendar
7
+ [![version](https://img.shields.io/npm/v/ionic8-calendar/latest.svg)](https://www.npmjs.com/package/ionic8-calendar)
8
+ [![GitHub License](https://img.shields.io/npm/l/ionic2-calendar.svg)](https://raw.githubusercontent.com/pieninck/Ionic2-Calendar/master/LICENSE)
9
+
10
+ # Table of Contents
11
+ 1. [Demo](#demo)
12
+ 2. [Dependency](#dependency)
13
+ 3. [Usage](#usage)
14
+ 4. [Options](#options)
15
+ 5. [Callback](#callback)
16
+ 6. [View Customization Option](#view-customization-option)
17
+ 7. [EventSource](#eventsource)
18
+ 8. [Performance Tuning](#performance-tuning)
19
+ 9. [Common Questions](#common-questions)
20
+
21
+ # Demo
22
+ Version 2.0
23
+ https://stackblitz.com/edit/ionic-calendar-demo-2-2?file=src%2Fapp%2Fexample.component.html
24
+ Version 1.0
25
+ https://stackblitz.com/edit/ionic-calendar-demo-1-0?file=src%2Fapp%2Fexample.component.html
26
+ Version 0.x
27
+ https://stackblitz.com/edit/ionic-calendar-demo?file=pages%2Fhome%2Fhome.html
28
+
29
+
30
+
31
+ # Dependency
32
+ | Calendar Version | Ionic Version | Angular Version | Swiper Version |
33
+ | ------------- | ------------- | ------------- | ------------- |
34
+ | 2.8.x | >=8.0.0 | >=21.0.0 | >=11.0.0 |
35
+ | 2.7.x | >=8.0.0 | >=20.0.0 | >=11.0.0 |
36
+ | 2.6.x | >=8.0.0 | >=19.0.0 | >=11.0.0 |
37
+ | 2.5.x | >=8.0.0 | >=18.0.0 | >=11.0.0 |
38
+ | 2.4.x | >=7.0.0 | >=17.0.0 | >=11.0.0 |
39
+ | 2.3.x | >=7.0.0 | >=17.0.0 | >=11.0.0 |
40
+ | 2.2.x | >=7.0.0 | >=1s7.0.0 | >=10.1.0 |
41
+ | 2.1.x | >=7.0.0 | >=16.0.0 | >=10.1.0 |
42
+ | 2.0.x | >=7.0.0 | >=16.0.0 | [8.4.6, 9.0.0) |
43
+ | 1.0.x | >=6.1.9 | >=15.1.2 | [8.4.6, 9.0.0) |
44
+ | 0.6.x | >=5.1.0 | >=9.1.0 | |
45
+ | 0.5.x | >=4.0.0-rc.1 | | |
46
+ | 0.4.x | >=3.9.2 | | |
47
+ | 0.3.x | >=3.1.1 | | |
48
+ | 0.2.9+ | >=2.3.0 | | |
49
+ | 0.2.x | 2.0.0-rc.5 | | |
50
+ | 0.1.x | [2.0.0-rc.1, 2.0.0-rc.4] | | |
51
+
52
+ version 0.2-0.4 has below dependency:
53
+ intl 1.2.5, due to issue https://github.com/angular/angular/issues/3333
54
+
55
+ **Angular 21 note:** starting with `2.8.x` you need Angular CLI/Framework 21+, TypeScript `5.9.x`, and a `bundler` `moduleResolution` in `tsconfig.json`. Install `rimraf` (already listed in devDependencies) to keep the build scripts cross-platform.
56
+
57
+ ## Maintainer publish flow
58
+ 1. `npm run build`
59
+ 2. `npm publish ./dist --access public`
60
+ 3. Tag the release (`git tag vX.Y.Z && git push origin vX.Y.Z`)
61
+
62
+
63
+ # Usage
64
+
65
+ ## 1. Install Calendar Dependency
66
+ `npm install @pieninck/ionic2-calendar --save`
67
+
68
+ If you need the legacy npm name published by the original maintainer, install `ionic2-calendar`. Both packages expose the same API, but `@pieninck/ionic2-calendar` is this fork with Angular 21 support.
69
+
70
+ > **Note:** Throughout this README the snippets still reference `ionic2-calendar`. When consuming this fork, replace those import paths with `@pieninck/ionic2-calendar`.
71
+
72
+ ### version 1.0.x onwards
73
+ version 1.0.x is also published as Ionic6-Calendar package name. So could also run
74
+ `npm install ionic6-calendar --save`
75
+ version 2.0.+ is also published as Ionic7-Calendar package name. So could also run
76
+ `npm install ionic7-calendar --save`
77
+ version 2.5.+ is also published as Ionic8-Calendar package name. So could also run
78
+ `npm install ionic8-calendar --save`
79
+
80
+ <font color=red>**NOTE: Starting from Version 1.0.x, the underlying implementaion is based on Swiper instead of IonSlides, so also needs to install Swiper dependency.**</font>
81
+ - Install swiper dependency
82
+ `npm install swiper --save`
83
+
84
+ - Import swiper css in **global.scss**
85
+ ```
86
+ @import 'swiper/css';
87
+ ```
88
+
89
+ ## 2. Import the Calendar module
90
+ If using version 1.0.x, could use both ionic2-calendar or ionic6-calendar, ionic7-calendar.
91
+
92
+ - version 0.5.x onwards
93
+ ``` typescript
94
+ import { NgModule } from '@angular/core';
95
+ import { IonicApp, IonicModule } from '@ionic/angular';
96
+ import { MyApp } from './app/app.component';
97
+ import { NgCalendarModule } from 'ionic2-calendar';
98
+
99
+ @NgModule({
100
+ declarations: [
101
+ MyApp
102
+ ],
103
+ imports: [
104
+ NgCalendarModule,
105
+ IonicModule.forRoot(MyApp)
106
+ ],
107
+ bootstrap: [IonicApp],
108
+ entryComponents: [
109
+ MyApp
110
+ ]
111
+ })
112
+ export class AppModule {}
113
+ ```
114
+
115
+ - version 0.1.x - 0.4.x
116
+ ``` typescript
117
+ import { NgModule } from '@angular/core';
118
+ import { IonicApp, IonicModule } from 'ionic-angular';
119
+ import { MyApp } from './app/app.component';
120
+ import { NgCalendarModule } from 'ionic2-calendar';
121
+
122
+ @NgModule({
123
+ declarations: [
124
+ MyApp
125
+ ],
126
+ imports: [
127
+ NgCalendarModule,
128
+ IonicModule.forRoot(MyApp)
129
+ ],
130
+ bootstrap: [IonicApp],
131
+ entryComponents: [
132
+ MyApp
133
+ ]
134
+ })
135
+ export class AppModule {}
136
+ ```
137
+
138
+ If you are using PageModule, you need to import the NgCalendarModule in your page module
139
+
140
+ ``` typescript
141
+ import { NgCalendarModule } from 'ionic2-calendar';
142
+
143
+ @NgModule({
144
+ declarations: [
145
+ MyPage
146
+ ],
147
+ imports: [
148
+ IonicPageModule.forChild(MyPage),
149
+ NgCalendarModule
150
+ ],
151
+ entryComponents: [
152
+ MyPage
153
+ ]
154
+ })
155
+ export class MyPageModule {}
156
+ ```
157
+
158
+ ## 3. Add the directive in the html page
159
+
160
+ ``` html
161
+ <calendar [eventSource]="eventSource"
162
+ [calendarMode]="calendar.mode"
163
+ [currentDate]="calendar.currentDate"
164
+ (onCurrentDateChanged)="onCurrentDateChanged($event)"
165
+ (onRangeChanged)="reloadSource(startTime, endTime)"
166
+ (onEventSelected)="onEventSelected($event)"
167
+ (onTitleChanged)="onViewTitleChanged($event)"
168
+ (onTimeSelected)="onTimeSelected($event)"
169
+ [step]="calendar.step">
170
+ </calendar>
171
+ ```
172
+
173
+
174
+ # Options
175
+
176
+ * formatDay
177
+ The format of the date displayed in the month view.
178
+ Default value: 'dd'
179
+ * formatDayHeader
180
+ The format of the header displayed in the month view.
181
+ Default value: 'EEE'
182
+ * formatDayTitle
183
+ The format of the title displayed in the day view.
184
+ Default value: 'MMMM dd, yyyy'
185
+ * formatWeekTitle
186
+ The format of the title displayed in the week view.
187
+ Default value: (version 0.1-0.3) 'MMMM yyyy, Week $n', (version 0.4+) 'MMMM yyyy, \'Week\' w'
188
+ * formatMonthTitle
189
+ The format of the title displayed in the month view.
190
+ Default value: 'MMMM yyyy'
191
+ * formatWeekViewDayHeader
192
+ The format of the header displayed in the week view.
193
+ Default value: 'EEE d'
194
+ * formatHourColumn
195
+ The format of the hour column displayed in the week and day view.
196
+ Default value: (version 0.1-0.3) 'j', (version 0.4+) 'ha'
197
+ * calendarMode
198
+ The initial mode of the calendar.
199
+ Default value: 'month'
200
+
201
+ ``` html
202
+ <calendar ... [calendarMode]="calendar.mode"></calendar>
203
+ ```
204
+
205
+ Version 1.0.x onwards
206
+ ```typescript
207
+ import { CalendarMode } from 'ionic2-calendar';
208
+
209
+ calendar = {
210
+ mode: 'week' as CalendarMode
211
+ };
212
+ ```
213
+
214
+ Version 0.x
215
+ ```typescript
216
+ import { CalendarMode } from 'ionic2-calendar/calendar';
217
+
218
+ calendar = {
219
+ mode: 'week' as CalendarMode
220
+ };
221
+ ```
222
+
223
+ * showEventDetail
224
+ If set to true, when selecting the date in the month view, the events happened on that day will be shown below.
225
+ Default value: true
226
+ * startingDayMonth
227
+ Control month view starting from which day.
228
+ Default value: 0 (Sunday)
229
+ * startingDayWeek
230
+ Control week view starting from which day.
231
+ Default value: 0 (Sunday)
232
+ * allDayLabel
233
+ The text displayed in the allDay column header of week and day view.
234
+ Default value: 'all day'
235
+ * noEventsLabel
236
+ The text displayed when there’s no event on the selected date in month view.
237
+ Default value: 'No Events'
238
+ * eventSource
239
+ The data source of the calendar, when the eventSource is set, the view will be updated accordingly.
240
+ Default value: null
241
+ The format of the eventSource is described in the [EventSource](#eventsource) section
242
+ * queryMode
243
+ If queryMode is set to 'local', when the range or mode is changed, the calendar will use the already bound eventSource to update the view
244
+ If queryMode is set to 'remote', when the range or mode is changed, the calendar will trigger a callback function rangeChanged.
245
+ Users will need to implement their custom loading data logic in this function, and fill it into the eventSource. The eventSource is watched, so the view will be updated once the eventSource is changed.
246
+ Default value: 'local'
247
+ * step
248
+ It is used to display the event using more accurate time interval in weekview and dayview. For example, if set to 30, then the event will only occupy half of the row height (If timeInterval option uses default value). The unit is minute. It can be set to 15 or 30.
249
+ Default value: 60
250
+ ``` html
251
+ <calendar ... [step]="calendar.step"></calendar>
252
+ ```
253
+
254
+ ```typescript
255
+ import { Step } from 'ionic2-calendar/calendar';
256
+
257
+ calendar = {
258
+ step: 30 as Step
259
+ };
260
+ ```
261
+
262
+ * timeInterval (version >= 0.3)
263
+ It is used to display the rows using more accurate time interval in weekview and dayview. For example, if set to 30, then the time interval between each row is 30 mins.
264
+ The unit is minute. It should be the factor or multiple of 60, which means 60%timeInterval=0 or timeInterval%60=0.
265
+ Default value: 60
266
+ ``` html
267
+ <calendar ... [timeInterval]="30"></calendar>
268
+ ```
269
+
270
+ * autoSelect
271
+ If set to true, the current calendar date will be auto selected when calendar is loaded or swiped in the month and week view.
272
+ Default value: true
273
+ * locale
274
+ The locale used to display text in the calendar.
275
+ Check [Localization](#localization) section for more details.
276
+ Default value: undefined (which means the local language)
277
+ ``` html
278
+ <calendar ... [locale]="calendar.locale"></calendar>
279
+ ```
280
+ ``` typescript
281
+ calendar = {
282
+ locale: 'en-GB'
283
+ };
284
+ ```
285
+ * markDisabled
286
+ The callback function used to determine if the time should be marked as disabled.
287
+ ``` html
288
+ <calendar ... [markDisabled]="markDisabled"></calendar>
289
+ ```
290
+ ``` typescript
291
+ markDisabled = (date: Date) => {
292
+ var current = new Date();
293
+ return date < current;
294
+ };
295
+ ```
296
+ * dateFormatter
297
+ The custom date formatter to transform date to text.
298
+ If the custom date formatter is not set, the default Angular DatePipe is used.
299
+ The format method in dateFormatter is optional, if omitted, the default Angular DatePipe is used.
300
+ ``` html
301
+ <calendar ... [dateFormatter]="calendar.dateFormatter"></calendar>
302
+ ```
303
+ ``` typescript
304
+ calendar = {
305
+ dateFormatter: {
306
+ formatMonthViewDay: function(date:Date) {
307
+ return date.getDate().toString();
308
+ },
309
+ formatMonthViewDayHeader: function(date:Date) {
310
+ return 'testMDH';
311
+ },
312
+ formatMonthViewTitle: function(date:Date) {
313
+ return 'testMT';
314
+ },
315
+ formatWeekViewDayHeader: function(date:Date) {
316
+ return 'testWDH';
317
+ },
318
+ formatWeekViewTitle: function(date:Date) {
319
+ return 'testWT';
320
+ },
321
+ formatWeekViewHourColumn: function(date:Date) {
322
+ return 'testWH';
323
+ },
324
+ formatDayViewHourColumn: function(date:Date) {
325
+ return 'testDH';
326
+ },
327
+ formatDayViewTitle: function(date:Date) {
328
+ return 'testDT';
329
+ }
330
+ }
331
+ };
332
+ ```
333
+ * dir
334
+ If set to "rtl", the calendar supports RTL language. This feature is only supported in Ionic 2.3.0 version onwards.
335
+ Default value: ""
336
+
337
+ * scrollToHour
338
+ Make weekview and dayview scroll to the specific hour after entering to the new view.
339
+ Default value: 0
340
+
341
+ * preserveScrollPosition
342
+ If set to true, the previous/next views in weekview and dayview will also scroll to the same position as the current active view.
343
+ Default value: false
344
+
345
+ * lockSwipeToPrev
346
+ If set to true, swiping to previous view is disabled.
347
+ Default value: false
348
+ ``` html
349
+ <calendar ... [lockSwipeToPrev]="lockSwipeToPrev"></calendar>
350
+ ```
351
+ ``` typescript
352
+ onCurrentDateChanged(event:Date) {
353
+ var today = new Date();
354
+ today.setHours(0, 0, 0, 0);
355
+ event.setHours(0, 0, 0, 0);
356
+
357
+ if (this.calendar.mode === 'month') {
358
+ if (event.getFullYear() < today.getFullYear() || (event.getFullYear() === today.getFullYear() && event.getMonth() <= today.getMonth())) {
359
+ this.lockSwipeToPrev = true;
360
+ } else {
361
+ this.lockSwipeToPrev = false;
362
+ }
363
+ }
364
+ }
365
+ ```
366
+
367
+ * lockSwipeToNext (version 1.0.x onwards)
368
+ If set to true, swiping to next view is disabled.
369
+ Default value: false
370
+ ``` html
371
+ <calendar ... [lockSwipeToNext]="lockSwipeToNext"></calendar>
372
+ ```
373
+ ``` typescript
374
+ onCurrentDateChanged(event:Date) {
375
+ var today = new Date();
376
+ today.setHours(0, 0, 0, 0);
377
+ event.setHours(0, 0, 0, 0);
378
+
379
+ if (this.calendar.mode === 'month') {
380
+ if (event.getFullYear() > today.getFullYear() || (event.getFullYear() === today.getFullYear() && event.getMonth() >= today.getMonth())) {
381
+ this.lockSwipeToNext = true;
382
+ } else {
383
+ this.lockSwipeToNext = false;
384
+ }
385
+ }
386
+ }
387
+ ```
388
+
389
+
390
+ * lockSwipes
391
+ If set to true, swiping is disabled.
392
+ Default value: false
393
+
394
+ **Version 1.x**
395
+ *Note:* Since swiping is disabled, you could set currentDate or call slideToPrev/slideToNext [method](#instance-methods) to move the calendar to previous/next view. You need to first set the lockSwipes to false, move the slide, then set it back.
396
+ ``` html
397
+ <calendar ... [lockSwipes]="lockSwipes"></calendar>
398
+ ```
399
+ ``` typescript
400
+ moveSlide() {
401
+ this.calendar.lockSwipes = false;
402
+ setTimeout(function() {
403
+ this.myCalendar.slideNext();
404
+ this.calendar.lockSwipes = true;
405
+ },100);
406
+ }
407
+ ```
408
+
409
+ **Version 0.x**
410
+ *Note:* Since swiping is disabled, you could set currentDate or call slideToPrev/slideToNext [method](#instance-methods) to move the calendar to previous/next view. Do not set lockSwipeToPrev in the constructor phase. It will cause the view not updating when changing the currentDate. You could either set it in some callback function after initialization phase or use setTimeout to trigger some delay.
411
+ ``` html
412
+ <calendar ... [lockSwipes]="lockSwipes"></calendar>
413
+ ```
414
+ ``` typescript
415
+ ngAfterViewInit() {
416
+ var me = this;
417
+ setTimeout(function() {
418
+ me.lockSwipes = true;
419
+ },100);
420
+ }
421
+ ```
422
+
423
+ * startHour
424
+ Limit the weekview and dayview starts from which hour (0-23).
425
+ Default value: 0
426
+ ``` html
427
+ <calendar ... startHour="9"></calendar>
428
+ ```
429
+
430
+ * endHour
431
+ Limit the weekview and dayview ends until which hour (1-24).
432
+ Default value: 24
433
+ ``` html
434
+ <calendar ... endHour="19"></calendar>
435
+ ```
436
+
437
+ * sliderOptions
438
+ Options to pass to the underlying swiper instance. See https://swiperjs.com/swiper-api#parameters for valid options.
439
+ ``` html
440
+ <calendar ... sliderOptions="sliderOptions"></calendar>
441
+ ```
442
+ ``` typescript
443
+ options = {
444
+ spaceBetween: 10,
445
+ threshold: 50
446
+ };
447
+ ```
448
+
449
+ * `dayviewShowCategoryView` (version: 2.4+)
450
+ Determines if show dayview with category
451
+ Type: `boolean`
452
+ Default value: `false`
453
+
454
+
455
+ * `dayviewCategorySource` (version: 2.4+)
456
+ Determines the source the category names so that events with corresponding category will display accordingly. If events are not assigned with category, they will NOT be placed in the category view.
457
+ Type: `Set<string>`
458
+ Default value: `null`
459
+ ``` html
460
+ <calendar ... [dayviewCategorySource]="calendar.dayviewCategorySource"></calendar>
461
+ ```
462
+ ``` typescript
463
+ calendar = {
464
+ dayviewCategorySource: new Set<string>(['Alice', 'Bob', 'Charlie'])
465
+ };
466
+ ```
467
+
468
+ # Callback
469
+ * onCurrentDateChanged
470
+ The callback function triggered when the date that is currently viewed changes.
471
+ ``` html
472
+ <calendar ... (onCurrentDateChanged)="onCurrentDateChanged($event)"></calendar>
473
+ ```
474
+ ``` typescript
475
+ onCurrentChanged = (ev: Date) => {
476
+ console.log('Currently viewed date: ' + ev);
477
+ };
478
+ ```
479
+ * onRangeChanged
480
+ The callback function triggered when the range or mode is changed if the **queryMode** is set to '**remote**'
481
+ The ev parameter contains two fields, startTime and endTime.
482
+ ``` html
483
+ <calendar ... (onRangeChanged)="onRangeChanged($event)"></calendar>
484
+ ```
485
+ ``` typescript
486
+ onRangeChanged = (ev: { startTime: Date, endTime: Date }) => {
487
+ Events.query(ev, (events) => {
488
+ this.eventSource = events;
489
+ });
490
+ };
491
+ ```
492
+ * onEventSelected
493
+ The callback function triggered when an event is clicked
494
+ ``` html
495
+ <calendar ... (onEventSelected)="onEventSelected($event)"></calendar>
496
+ ```
497
+ ``` typescript
498
+ onEventSelected = (event) => {
499
+ console.log(event.title);
500
+ };
501
+ ```
502
+ * onTimeSelected
503
+ The callback function triggered when a time slot is selected.
504
+ The ev parameter contains three fields, selectedTime, events and disabled, if there's no event at the selected time, the events field will be either undefined or empty array
505
+ ``` html
506
+ <calendar ... (onTimeSelected)="onTimeSelected($event)"></calendar>
507
+ ```
508
+ ``` typescript
509
+ onTimeSelected = (ev: { selectedTime: Date, events: any[], disabled: boolean }) => {
510
+ console.log('Selected time: ' + ev.selectedTime + ', hasEvents: ' + (ev.events !== undefined && ev.events.length !== 0) + ', disabled: ' + ev.disabled);
511
+ };
512
+ ```
513
+ * onDayHeaderSelected
514
+ The callback function triggered when a day header is selected in week view.
515
+ The ev parameter contains three fields, selectedTime, events and disabled, if there's no event at the selected time, the events field will be either undefined or empty array
516
+ ``` html
517
+ <calendar ... (onDayHeaderSelected)="onDayHeaderSelected($event)"></calendar>
518
+ ```
519
+ ``` typescript
520
+ onDayHeaderSelected = (ev: { selectedTime: Date, events: any[], disabled: boolean }) => {
521
+ console.log('Selected day: ' + ev.selectedTime + ', hasEvents: ' + (ev.events !== undefined && ev.events.length !== 0) + ', disabled: ' + ev.disabled);
522
+ };
523
+ ```
524
+ * onTitleChanged
525
+ The callback function triggered when the view title is changed
526
+ ``` html
527
+ <calendar ... (onTitleChanged)="onViewTitleChanged($event)"></calendar>
528
+ ```
529
+ ``` typescript
530
+ onViewTitleChanged = (title: string) => {
531
+ this.viewTitle = title;
532
+ };
533
+ ```
534
+ # View Customization Option
535
+ There are two ways to customize the look and feel. If you just want to simply change the color or size of certain element, you could override the styles of the predefined css classes. **CSS Customization** section lists some important css classes. If you need to change the layout of certain element, you could refer to the **Template Customization** part.
536
+
537
+ ## CSS Customization
538
+ The customized styles should be added in global.scss. Just adding in each components css file may not work due to the View Encapsulation.
539
+
540
+ * monthview-primary-with-event
541
+ The date that is in current month and having events
542
+
543
+ * monthview-secondary-with-event
544
+ The date that is in previous/next month and having events
545
+
546
+ * monthview-selected
547
+ The selected date
548
+
549
+ * monthview-current
550
+ The current date
551
+
552
+ * monthview-disabled
553
+ The disabled date
554
+
555
+ * weekview-with-event
556
+ The date having all day events, applied to the day header in week view
557
+
558
+ * weekview-current
559
+ The current date, applied to the day header in week view
560
+
561
+ * weekview-selected
562
+ The selected date, applied to the day header in week view
563
+
564
+ * weekview-allday-label
565
+ Applied to the all day label in week view
566
+
567
+ * dayview-allday-label
568
+ Applied to the all day label in day view
569
+
570
+ * calendar-hour-column
571
+ Applied to the hour column in both weekview and day view
572
+
573
+ * dayview-category-header (version: 2.4+)
574
+ Applied to the category section in day view
575
+
576
+ * dayview-category-header-item (version: 2.4+)
577
+ Applied to the category header item in day view
578
+
579
+ ## Template Customization
580
+
581
+ Note: For any css class appear in the customized template, you need to specify the styles by yourself. The styles defined in the calendar component won’t be applied because of the view encapsulation. You could refer to calendar.ts to get the definition of context types.
582
+
583
+ * monthviewDisplayEventTemplate
584
+ Type: TemplateRef\<IMonthViewDisplayEventTemplateContext\>
585
+ The template provides customized view for event displayed in the active monthview
586
+ ``` html
587
+ <ng-template #monthviewDisplayEventTemplate let-view="view" let-row="row" let-col="col">
588
+ {{view.dates[row*7+col].label}}
589
+ </ng-template>
590
+
591
+ <calendar ... [monthviewDisplayEventTemplate]="monthviewDisplayEventTemplate"></calendar>
592
+ ```
593
+ * monthviewInactiveDisplayEventTemplate
594
+ Type: TemplateRef\<IMonthViewDisplayEventTemplateContext\>
595
+ The template provides customized view for event displayed in the inactive monthview
596
+ ``` html
597
+ <ng-template #monthviewInactiveDisplayEventTemplate let-view="view" let-row="row" let-col="col">
598
+ {{view.dates[row*7+col].label}}
599
+ </ng-template>
600
+
601
+ <calendar ... [monthviewInactiveDisplayEventTemplate]="monthviewInactiveDisplayEventTemplate"></calendar>
602
+ ```
603
+ * monthviewEventDetailTemplate
604
+ Type: TemplateRef\<IMonthViewEventDetailTemplateContext\>
605
+ The template provides customized view for event detail section in the monthview
606
+ ``` html
607
+ <ng-template #monthviewEventDetailTemplate let-showEventDetail="showEventDetail" let-selectedDate="selectedDate" let-noEventsLabel="noEventsLabel">
608
+ ...
609
+ </ng-template>
610
+
611
+ <calendar ... [monthviewEventDetailTemplate]="monthviewEventDetailTemplate"></calendar>
612
+ ```
613
+ * weekviewHeaderTemplate (version >= 0.4.5)
614
+ Type: TemplateRef\<IDisplayWeekViewHeader\>
615
+ The template provides customized view for day header in the weekview
616
+ ``` html
617
+ <ng-template #weekviewHeaderTemplate let-viewDate="viewDate">
618
+ <div class="custom-day-header"> {{ viewDate.dayHeader }} </div>
619
+ </ng-template>
620
+
621
+ <calendar ... [weekviewHeaderTemplate]="weekviewHeaderTemplate"></calendar>
622
+ ```
623
+ * weekviewAllDayEventTemplate
624
+ Type: TemplateRef\<IDisplayAllDayEvent\>
625
+ The template provides customized view for all day event in the weekview
626
+ ``` html
627
+ <ng-template #weekviewAllDayEventTemplate let-displayEvent="displayEvent">
628
+ <div class="calendar-event-inner">{{displayEvent.event.title}}</div>
629
+ </ng-template>
630
+
631
+ <calendar ... [weekviewAllDayEventTemplate]="weekviewAllDayEventTemplate"></calendar>
632
+ ```
633
+ * weekviewNormalEventTemplate
634
+ Type: TemplateRef\<IDisplayEvent\>
635
+ The template provides customized view for normal event in the weekview
636
+
637
+ ``` html
638
+ <ng-template #weekviewNormalEventTemplate let-displayEvent="displayEvent">
639
+ <div class="calendar-event-inner">{{displayEvent.event.title}}</div>
640
+ </ng-template>
641
+
642
+ <calendar ... [weekviewNormalEventTemplate]="weekviewNormalEventTemplate"></calendar>
643
+ ```
644
+
645
+ * dayviewCategoryItemTemplate (version: 2.4+)
646
+ The template provides customized view for category item with categoryId and categoryName in the day view
647
+ ``` html
648
+ <ng-template #dayviewCategoryItemTemplate let-category="category">
649
+ {{ category.categoryName }}
650
+ </ng-template>
651
+
652
+ <calendar ... [dayviewCategoryItemTemplate]="dayviewCategoryItemTemplate"></calendar>
653
+ ```
654
+
655
+ * dayviewAllDayEventTemplate
656
+ Type: TemplateRef\<IDisplayAllDayEvent\>
657
+ The template provides customized view for all day event in the dayview
658
+ ``` html
659
+ <ng-template #dayviewAllDayEventTemplate let-displayEvent="displayEvent">
660
+ <div class="calendar-event-inner">{{displayEvent.event.title}}</div>
661
+ </ng-template>
662
+
663
+ <calendar ... [dayviewAllDayEventTemplate]="dayviewAllDayEventTemplate"></calendar>
664
+ ```
665
+
666
+ * dayviewNormalEventTemplate
667
+ Type: TemplateRef\<IDisplayEvent\>
668
+ The template provides customized view for normal event in the dayview
669
+
670
+ ``` html
671
+ <ng-template #dayviewNormalEventTemplate let-displayEvent="displayEvent">
672
+ <div class="calendar-event-inner">{{displayEvent.event.title}}</div>
673
+ </ng-template>
674
+
675
+ <calendar ... [dayviewNormalEventTemplate]="dayviewNormalEventTemplate"></calendar>
676
+ ```
677
+
678
+ * weekviewAllDayEventSectionTemplate (version >= 0.3)
679
+ Type: TemplateRef\<IWeekViewAllDayEventSectionTemplateContext\>
680
+ The template provides customized view for all day event section (table part) in the weekview
681
+
682
+ ``` html
683
+ <ng-template #weekviewAllDayEventSectionTemplate let-day="day" let-eventTemplate="eventTemplate">
684
+ <div [ngClass]="{'calendar-event-wrap': day.events}" *ngIf="day.events"
685
+ [ngStyle]="{height: 25*day.events.length+'px'}">
686
+ <div *ngFor="let displayEvent of day.events" class="calendar-event" tappable
687
+ (click)="onEventSelected(displayEvent.event)"
688
+ [ngStyle]="{top: 25*displayEvent.position+'px', width: 100*(displayEvent.endIndex-displayEvent.startIndex)+'%', height: '25px'}">
689
+ <ng-template [ngTemplateOutlet]="eventTemplate"
690
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}">
691
+ </ng-template>
692
+ </div>
693
+ </div>
694
+ </ng-template>
695
+
696
+ <calendar ... [weekviewAllDayEventSectionTemplate]="weekviewAllDayEventSectionTemplate"></calendar>
697
+ ```
698
+
699
+ * weekviewNormalEventSectionTemplate (version >= 0.3)
700
+ Type: TemplateRef\<IWeekViewNormalEventSectionTemplateContext\>
701
+ The template provides customized view for normal event section (table part) in the weekview
702
+
703
+ ``` html
704
+ <ng-template #weekviewNormalEventSectionTemplate let-tm="tm" let-hourParts="hourParts" let-eventTemplate="eventTemplate">
705
+ <div [ngClass]="{'calendar-event-wrap': tm.events}" *ngIf="tm.events">
706
+ <div *ngFor="let displayEvent of tm.events" class="calendar-event" tappable
707
+ (click)="onEventSelected(displayEvent.event)"
708
+ [ngStyle]="{top: (37*displayEvent.startOffset/hourParts)+'px',left: 100/displayEvent.overlapNumber*displayEvent.position+'%', width: 100/displayEvent.overlapNumber+'%', height: 37*(displayEvent.endIndex -displayEvent.startIndex - (displayEvent.endOffset + displayEvent.startOffset)/hourParts)+'px'}">
709
+ <ng-template [ngTemplateOutlet]="eventTemplate"
710
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}">
711
+ </ng-template>
712
+ </div>
713
+ </div>
714
+ </ng-template>
715
+
716
+ <calendar ... [weekviewNormalEventSectionTemplate]="weekviewNormalEventSectionTemplate"></calendar>
717
+ ```
718
+
719
+ * dayviewAllDayEventSectionTemplate (version >= 0.3)
720
+ Type: TemplateRef\<IDayViewAllDayEventSectionTemplateContext\>
721
+ The template provides customized view for all day event section (table part) in the dayview
722
+
723
+ ``` html
724
+ <ng-template #dayviewAllDayEventSectionTemplate let-allDayEvents="allDayEvents" let-eventTemplate="eventTemplate">
725
+ <div *ngFor="let displayEvent of allDayEvents; let eventIndex=index"
726
+ class="calendar-event" tappable
727
+ (click)="onEventSelected(displayEvent.event)"
728
+ [ngStyle]="{top: 25*eventIndex+'px',width: '100%',height:'25px'}">
729
+ <ng-template [ngTemplateOutlet]="eventTemplate"
730
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}">
731
+ </ng-template>
732
+ </div>
733
+ </ng-template>
734
+
735
+ <calendar ... [dayviewAllDayEventSectionTemplate]="dayviewAllDayEventSectionTemplate"></calendar>
736
+ ```
737
+
738
+ * dayviewNormalEventSectionTemplate (version >= 0.3)
739
+ Type: TemplateRef\<IDayViewNormalEventSectionTemplateContext\>
740
+ The template provides customized view for normal event section (table part) in the dayview
741
+
742
+ ``` html
743
+ <ng-template #dayviewNormalEventSectionTemplate let-tm="tm" let-hourParts="hourParts" let-eventTemplate="eventTemplate">
744
+ <div [ngClass]="{'calendar-event-wrap': tm.events}" *ngIf="tm.events">
745
+ <div *ngFor="let displayEvent of tm.events" class="calendar-event" tappable
746
+ (click)="onEventSelected(displayEvent.event)"
747
+ [ngStyle]="{top: (37*displayEvent.startOffset/hourParts)+'px',left: 100/displayEvent.overlapNumber*displayEvent.position+'%', width: 100/displayEvent.overlapNumber+'%', height: 37*(displayEvent.endIndex -displayEvent.startIndex - (displayEvent.endOffset + displayEvent.startOffset)/hourParts)+'px'}">
748
+ <ng-template [ngTemplateOutlet]="eventTemplate"
749
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}">
750
+ </ng-template>
751
+ </div>
752
+ </div>
753
+ </ng-template>
754
+
755
+ <calendar ... [dayviewNormalEventSectionTemplate]="dayviewNormalEventSectionTemplate"></calendar>
756
+ ```
757
+
758
+ * weekviewInactiveAllDayEventSectionTemplate (version >= 0.5)
759
+ Type: TemplateRef\<IWeekViewAllDayEventSectionTemplateContext\>
760
+ The template provides customized view for all day event section (table part) in the inactive weekview
761
+
762
+ ``` html
763
+ <ng-template #weekviewInactiveAllDayEventSectionTemplate let-day="day" let-eventTemplate="eventTemplate">
764
+ <div [ngClass]="{'calendar-event-wrap': day.events}" *ngIf="day.events"
765
+ [ngStyle]="{height: 25*day.events.length+'px'}">
766
+ <div *ngFor="let displayEvent of day.events" class="calendar-event" tappable
767
+ (click)="onEventSelected(displayEvent.event)"
768
+ [ngStyle]="{top: 25*displayEvent.position+'px', width: 100*(displayEvent.endIndex-displayEvent.startIndex)+'%', height: '25px'}">
769
+ <ng-template [ngTemplateOutlet]="eventTemplate"
770
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}">
771
+ </ng-template>
772
+ </div>
773
+ </div>
774
+ </ng-template>
775
+
776
+        <calendar ... [weekviewInactiveAllDayEventSectionTemplate]="weekviewInactiveAllDayEventSectionTemplate"></calendar>
777
+ ```
778
+
779
+ * weekviewInactiveNormalEventSectionTemplate (version >= 0.5)
780
+ Type: TemplateRef\<IWeekViewNormalEventSectionTemplateContext\>
781
+ The template provides customized view for normal event section (table part) in the inactive weekview
782
+
783
+ ``` html
784
+ <ng-template #weekviewInactiveNormalEventSectionTemplate let-tm="tm" let-hourParts="hourParts" let-eventTemplate="eventTemplate">
785
+ <div [ngClass]="{'calendar-event-wrap': tm.events}" *ngIf="tm.events">
786
+ <div *ngFor="let displayEvent of tm.events" class="calendar-event" tappable
787
+ (click)="onEventSelected(displayEvent.event)"
788
+ [ngStyle]="{top: (37*displayEvent.startOffset/hourParts)+'px',left: 100/displayEvent.overlapNumber*displayEvent.position+'%', width: 100/displayEvent.overlapNumber+'%', height: 37*(displayEvent.endIndex -displayEvent.startIndex - (displayEvent.endOffset + displayEvent.startOffset)/hourParts)+'px'}">
789
+ <ng-template [ngTemplateOutlet]="eventTemplate"
790
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}">
791
+ </ng-template>
792
+ </div>
793
+ </div>
794
+ </ng-template>
795
+
796
+        <calendar ... [weekviewInactiveNormalEventSectionTemplate]="weekviewInactiveNormalEventSectionTemplate"></calendar>
797
+ ```
798
+
799
+ * dayviewInactiveAllDayEventSectionTemplate (version >= 0.5)
800
+ Type: TemplateRef\<IDayViewAllDayEventSectionTemplateContext\>
801
+ The template provides customized view for all day event section (table part) in the inactive dayview
802
+
803
+ ``` html
804
+ <ng-template #dayviewInactiveAllDayEventSectionTemplate let-allDayEvents="allDayEvents" let-eventTemplate="eventTemplate">
805
+ <div *ngFor="let displayEvent of allDayEvents; let eventIndex=index"
806
+ class="calendar-event" tappable
807
+ (click)="onEventSelected(displayEvent.event)"
808
+ [ngStyle]="{top: 25*eventIndex+'px',width: '100%',height:'25px'}">
809
+ <ng-template [ngTemplateOutlet]="eventTemplate"
810
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}">
811
+ </ng-template>
812
+ </div>
813
+ </ng-template>
814
+
815
+        <calendar ... [dayviewInactiveAllDayEventSectionTemplate]="dayviewInactiveAllDayEventSectionTemplate"></calendar>
816
+ ```
817
+
818
+ * dayviewInactiveNormalEventSectionTemplate (version >= 0.5)
819
+ Type: TemplateRef\<IDayViewNormalEventSectionTemplateContext\>
820
+ The template provides customized view for normal event section (table part) in the inactive dayview
821
+
822
+ ``` html
823
+ <ng-template #dayviewInactiveNormalEventSectionTemplate let-tm="tm" let-hourParts="hourParts" let-eventTemplate="eventTemplate">
824
+ <div [ngClass]="{'calendar-event-wrap': tm.events}" *ngIf="tm.events">
825
+ <div *ngFor="let displayEvent of tm.events" class="calendar-event" tappable
826
+ (click)="onEventSelected(displayEvent.event)"
827
+ [ngStyle]="{top: (37*displayEvent.startOffset/hourParts)+'px',left: 100/displayEvent.overlapNumber*displayEvent.position+'%', width: 100/displayEvent.overlapNumber+'%', height: 37*(displayEvent.endIndex -displayEvent.startIndex - (displayEvent.endOffset + displayEvent.startOffset)/hourParts)+'px'}">
828
+ <ng-template [ngTemplateOutlet]="eventTemplate"
829
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}">
830
+ </ng-template>
831
+ </div>
832
+ </div>
833
+ </ng-template>
834
+
835
+        <calendar ... [dayviewInactiveNormalEventSectionTemplate]="dayviewInactiveNormalEventSectionTemplate"></calendar>
836
+ ```
837
+
838
+
839
+ # EventSource
840
+
841
+ EventSource is an array of event object which contains at least below fields:
842
+
843
+ * title
844
+ Type: `string`
845
+
846
+ * startTime
847
+ Type: `Date`
848
+ If allDay is set to true, the startTime has to be as a UTC date which time is set to 0:00 AM, because in an allDay event, only the date is considered, the exact time or timezone doesn't matter.
849
+ For example, if an allDay event starting from 2014-05-09, then startTime is
850
+
851
+ ``` javascript
852
+ var startTime = new Date(Date.UTC(2014, 4, 8));
853
+ ```
854
+
855
+ * endTime
856
+ Type: `Date`
857
+ If allDay is set to true, the startTime has to be as a UTC date which time is set to 0:00 AM, because in an allDay event, only the date is considered, the exact time or timezone doesn't matter.
858
+ For example, if an allDay event ending to 2014-05-10, then endTime is
859
+ ``` javascript
860
+ var endTime = new Date(Date.UTC(2014, 4, 9));
861
+ ```
862
+ * allDay
863
+ Type: `boolean`
864
+ Indicates the event is allDay event or regular event
865
+
866
+ * category (optional)
867
+ Type: `string`
868
+ Indicates which category the event belongs to. If the value is specified but not one of `dayviewCategorySource`, the event will not display in category view.
869
+
870
+ **Note** The calendar only watches for the eventSource reference for performance consideration. That means only you manually reassign the eventSource value, the calendar gets notified, and this is usually fit to the scenario when the range is changed, you load a new data set from the backend. In case you want to manually insert/remove/update the element in the eventSource array, you can call [instance method](#instance-methods) ‘loadEvents’ event to notify the calendar manually.
871
+
872
+ # Instance Methods
873
+ * loadEvents
874
+ When this method is called, the calendar will be forced to reload the events in the eventSource array. This is only necessary when you directly modify the element in the eventSource array.
875
+
876
+ ``` typescript
877
+ import { CalendarComponent } from "ionic2-calendar";
878
+
879
+ @Component({
880
+ selector: 'page-home',
881
+ templateUrl: 'home.html'
882
+ })
883
+ export class HomePage {
884
+ @ViewChild(CalendarComponent, null) myCalendar:CalendarComponent;
885
+ eventSource;
886
+
887
+ loadEvents: function() {
888
+ this.eventSource.push({
889
+ title: 'test',
890
+ startTime: startTime,
891
+ endTime: endTime,
892
+ allDay: false
893
+ });
894
+ this.myCalendar.loadEvents();
895
+ }
896
+ }
897
+ ```
898
+
899
+ * slideNext (version >= 0.5)
900
+ Slide the calendar to the next date range.
901
+
902
+ ``` typescript
903
+ import { CalendarComponent } from "ionic2-calendar";
904
+
905
+ @Component({
906
+ selector: 'page-home',
907
+ templateUrl: 'home.html'
908
+ })
909
+ export class HomePage {
910
+ @ViewChild(CalendarComponent, null) myCalendar:CalendarComponent;
911
+
912
+ slideNext: function() {
913
+ this.myCalendar.slideNext();
914
+ }
915
+ }
916
+ ```
917
+
918
+ * slidePrev (version >= 0.5)
919
+ Slide the calendar to the previous date range.
920
+
921
+ ``` typescript
922
+ import { CalendarComponent } from "ionic2-calendar";
923
+
924
+ @Component({
925
+ selector: 'page-home',
926
+ templateUrl: 'home.html'
927
+ })
928
+ export class HomePage {
929
+ @ViewChild(CalendarComponent, null) myCalendar:CalendarComponent;
930
+
931
+ slidePrev: function() {
932
+ this.myCalendar.slidePrev();
933
+ }
934
+ }
935
+ ```
936
+
937
+ * update (version >= 0.6.5)
938
+ Update the underlying slides.
939
+
940
+ ``` typescript
941
+ import { CalendarComponent } from "ionic2-calendar";
942
+
943
+ @Component({
944
+ selector: 'page-home',
945
+ templateUrl: 'home.html'
946
+ })
947
+ export class HomePage {
948
+ @ViewChild(CalendarComponent, null) myCalendar:CalendarComponent;
949
+
950
+ slidePrev: function() {
951
+ this.myCalendar.update();
952
+ }
953
+ }
954
+ ```
955
+
956
+ # Localization
957
+ You could use *locale* option to achieve the localization.
958
+ If locale option is not specified, the calendar will use the LOCALE_ID set at the module level.
959
+ By default, the LOCALE_ID is **en-US**. You can override it in the module as below. If you pass **undefined**, the LOCALE_ID will be detected using the browser language setting. But using explicit value is recommended, as browser has different level of localization support.
960
+ Note that the event detail section in the month view doesn't support *locale* option, only LOCALE_ID takes effect. This is because it uses DatePipe in html directly. You could easily leverage customized event detail template to switch to other locale.
961
+
962
+ ``` typescript
963
+ import { NgModule, LOCALE_ID } from '@angular/core';
964
+
965
+ @NgModule({
966
+
967
+ providers: [
968
+ { provide: LOCALE_ID, useValue: 'zh-CN' }
969
+ ]
970
+ })
971
+ ```
972
+
973
+ For version 0.4.x+ which depends on Ionic 3.9.2+ and Angular 5.0+, locale module needs to be registered explicitly in module file as below.
974
+ ``` typescript
975
+ import { registerLocaleData } from '@angular/common';
976
+ import localeZh from '@angular/common/locales/zh';
977
+ registerLocaleData(localeZh);
978
+
979
+ ```
980
+
981
+ If you want to change the locale dynamically, you should use *locale* option instead of LOCALE_ID.
982
+
983
+ # Performance Tuning
984
+ In the CPU profile, the default Intl based localization code occupies a big portion of the execution time. If you don’t need localization on certain parts, you can use the custom dateFormatter to override the date transform method. For example, the date in month view usually doesn’t require localization, you could use below code to just display the date part. If the month view day header doesn’t need to include the date, you could also use a string array containing static labels to save the date calculation.
985
+
986
+ ``` html
987
+ <calendar ... [dateFormatter]="calendar.dateFormatter"></calendar>
988
+ ```
989
+ ``` typescript
990
+ calendar = {
991
+ dateFormatter: {
992
+ formatMonthViewDay: function(date:Date) {
993
+ return date.getDate().toString();
994
+ }
995
+ }
996
+ };
997
+ ```
998
+
999
+ # Known issue (No longer exists in version 1.0.x)
1000
+ This component updates the ion-slide dynamically so that only 3 looped slides are needed.
1001
+ The ion-slide in Ionic2 uses Swiper. It seems in the Swiper implementation, the next slide after the end of looped slide is a separate cached slide, instead of the first slide.
1002
+ I can't find out a way to force refresh that cached slide, so you will notice that when sliding from the third month to the forth month, the preview month is not the forth month, but the first month.
1003
+ Once the sliding is over, the slide will be forced to render the forth month.
1004
+
1005
+ # Common Questions
1006
+ * Error: Cannot find module "intl"
1007
+ Answer: This calendar has dependency on 'Intl'. Run *npm install intl@1.2.5* to install the dependency
1008
+
1009
+ * Error: Cannot read property 'getFullYear' of undefined
1010
+ Answer: If you bind currentDate like this: [currentDate]="calendar.currentDate". You need to assign calendar.currentDate a valid Date object
1011
+
1012
+ * How to switch the calendar to previous/next month programmatically?
1013
+ Answer: You can change currentDate to the date in previous/next month. You could also call the instance method slideNext/slidePrev.
1014
+
1015
+ * Error: Cannot read property 'dayHeaders' of undefined
1016
+ Answer: Take a look at the Localization section. For version 0.4.x+, you need to manually register the locale.
1017
+
1018
+ * Error: TypeError: event_1.startTime.getTime is not a function
1019
+ Answer: This is due to the startTime field of the event object is not a valid Date object. Be aware that different browser has different implementation of new Date() constructor. Some date string format may not be supported. It is recommended to use millisecond or year/month/date parameters.
1020
+
1021
+ * Error: How to override css
1022
+ Answer: By default, the css applied on each component is view encapsulated, for example, .table-bordered[_ngcontent-jto-c5]. You need to remove the encapsulated part.
1023
+ ```css
1024
+ .table-bordered[_ngcontent-jto-c5] {
1025
+ border: 1px solid #ddd !important;
1026
+ }
1027
+ ```