@pieninck/ionic2-calendar 3.0.1 → 4.0.0

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 CHANGED
@@ -1,1027 +1,1257 @@
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
- ```
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
+
12
+ 1. [Demo](#demo)
13
+ 2. [Dependency](#dependency)
14
+ 3. [Usage](#usage)
15
+ 4. [Options](#options)
16
+ 5. [Callback](#callback)
17
+ 6. [View Customization Option](#view-customization-option)
18
+ 7. [EventSource](#eventsource)
19
+ 8. [Performance Tuning](#performance-tuning)
20
+ 9. [Common Questions](#common-questions)
21
+
22
+ # Demo
23
+
24
+ Version 2.0
25
+ https://stackblitz.com/edit/ionic-calendar-demo-2-2?file=src%2Fapp%2Fexample.component.html
26
+ Version 1.0
27
+ https://stackblitz.com/edit/ionic-calendar-demo-1-0?file=src%2Fapp%2Fexample.component.html
28
+ Version 0.x
29
+ https://stackblitz.com/edit/ionic-calendar-demo?file=pages%2Fhome%2Fhome.html
30
+
31
+ # Dependency
32
+
33
+ | Calendar Version | Ionic Version | Angular Version | Swiper Version |
34
+ | ---------------- | ------------------------ | --------------- | -------------- |
35
+ | 2.8.x | >=8.0.0 | >=21.0.0 | >=11.0.0 |
36
+ | 2.7.x | >=8.0.0 | >=20.0.0 | >=11.0.0 |
37
+ | 2.6.x | >=8.0.0 | >=19.0.0 | >=11.0.0 |
38
+ | 2.5.x | >=8.0.0 | >=18.0.0 | >=11.0.0 |
39
+ | 2.4.x | >=7.0.0 | >=17.0.0 | >=11.0.0 |
40
+ | 2.3.x | >=7.0.0 | >=17.0.0 | >=11.0.0 |
41
+ | 2.2.x | >=7.0.0 | >=1s7.0.0 | >=10.1.0 |
42
+ | 2.1.x | >=7.0.0 | >=16.0.0 | >=10.1.0 |
43
+ | 2.0.x | >=7.0.0 | >=16.0.0 | [8.4.6, 9.0.0) |
44
+ | 1.0.x | >=6.1.9 | >=15.1.2 | [8.4.6, 9.0.0) |
45
+ | 0.6.x | >=5.1.0 | >=9.1.0 | |
46
+ | 0.5.x | >=4.0.0-rc.1 | | |
47
+ | 0.4.x | >=3.9.2 | | |
48
+ | 0.3.x | >=3.1.1 | | |
49
+ | 0.2.9+ | >=2.3.0 | | |
50
+ | 0.2.x | 2.0.0-rc.5 | | |
51
+ | 0.1.x | [2.0.0-rc.1, 2.0.0-rc.4] | | |
52
+
53
+ version 0.2-0.4 has below dependency:
54
+ intl 1.2.5, due to issue https://github.com/angular/angular/issues/3333
55
+
56
+ **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.
57
+
58
+ ## Maintainer publish flow
59
+
60
+ 1. `npm run build`
61
+ 2. `npm publish ./dist --access public`
62
+ 3. Tag the release (`git tag vX.Y.Z && git push origin vX.Y.Z`)
63
+
64
+ # Usage
65
+
66
+ ## 1. Install Calendar Dependency
67
+
68
+ `npm install @pieninck/ionic2-calendar --save`
69
+
70
+ 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.
71
+
72
+ > **Note:** Throughout this README the snippets still reference `ionic2-calendar`. When consuming this fork, replace those import paths with `@pieninck/ionic2-calendar`.
73
+
74
+ ### version 1.0.x onwards
75
+
76
+ version 1.0.x is also published as Ionic6-Calendar package name. So could also run
77
+ `npm install ionic6-calendar --save`
78
+ version 2.0.+ is also published as Ionic7-Calendar package name. So could also run
79
+ `npm install ionic7-calendar --save`
80
+ version 2.5.+ is also published as Ionic8-Calendar package name. So could also run
81
+ `npm install ionic8-calendar --save`
82
+
83
+ <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>
84
+
85
+ - Install swiper dependency
86
+ `npm install swiper --save`
87
+
88
+ - Import swiper css in **global.scss**
89
+
90
+ ```
91
+ @import 'swiper/css';
92
+ ```
93
+
94
+ ## 2. Import the Calendar module
95
+
96
+ If using version 1.0.x, could use both ionic2-calendar or ionic6-calendar, ionic7-calendar.
97
+
98
+ - version 0.5.x onwards
99
+
100
+ ```typescript
101
+ import { NgModule } from "@angular/core";
102
+ import { IonicApp, IonicModule } from "@ionic/angular";
103
+ import { MyApp } from "./app/app.component";
104
+ import { NgCalendarModule } from "ionic2-calendar";
105
+
106
+ @NgModule({
107
+ declarations: [MyApp],
108
+ imports: [NgCalendarModule, IonicModule.forRoot(MyApp)],
109
+ bootstrap: [IonicApp],
110
+ entryComponents: [MyApp],
111
+ })
112
+ export class AppModule {}
113
+ ```
114
+
115
+ - version 0.1.x - 0.4.x
116
+
117
+ ```typescript
118
+ import { NgModule } from "@angular/core";
119
+ import { IonicApp, IonicModule } from "ionic-angular";
120
+ import { MyApp } from "./app/app.component";
121
+ import { NgCalendarModule } from "ionic2-calendar";
122
+
123
+ @NgModule({
124
+ declarations: [MyApp],
125
+ imports: [NgCalendarModule, IonicModule.forRoot(MyApp)],
126
+ bootstrap: [IonicApp],
127
+ entryComponents: [MyApp],
128
+ })
129
+ export class AppModule {}
130
+ ```
131
+
132
+ If you are using PageModule, you need to import the NgCalendarModule in your page module
133
+
134
+ ```typescript
135
+ import { NgCalendarModule } from "ionic2-calendar";
136
+
137
+ @NgModule({
138
+ declarations: [MyPage],
139
+ imports: [IonicPageModule.forChild(MyPage), NgCalendarModule],
140
+ entryComponents: [MyPage],
141
+ })
142
+ export class MyPageModule {}
143
+ ```
144
+
145
+ ## 3. Add the directive in the html page
146
+
147
+ ```html
148
+ <calendar
149
+ [eventSource]="eventSource"
150
+ [calendarMode]="calendar.mode"
151
+ [currentDate]="calendar.currentDate"
152
+ (onCurrentDateChanged)="onCurrentDateChanged($event)"
153
+ (onRangeChanged)="reloadSource(startTime, endTime)"
154
+ (onEventSelected)="onEventSelected($event)"
155
+ (onTitleChanged)="onViewTitleChanged($event)"
156
+ (onTimeSelected)="onTimeSelected($event)"
157
+ [step]="calendar.step"
158
+ >
159
+ </calendar>
160
+ ```
161
+
162
+ # Options
163
+
164
+ - formatDay
165
+ The format of the date displayed in the month view.
166
+ Default value: 'dd'
167
+ - formatDayHeader
168
+ The format of the header displayed in the month view.
169
+ Default value: 'EEE'
170
+ - formatDayTitle
171
+ The format of the title displayed in the day view.
172
+ Default value: 'MMMM dd, yyyy'
173
+ - formatWeekTitle
174
+ The format of the title displayed in the week view.
175
+ Default value: (version 0.1-0.3) 'MMMM yyyy, Week $n', (version 0.4+) 'MMMM yyyy, \'Week\' w'
176
+ - formatMonthTitle
177
+ The format of the title displayed in the month view.
178
+ Default value: 'MMMM yyyy'
179
+ - formatWeekViewDayHeader
180
+ The format of the header displayed in the week view.
181
+ Default value: 'EEE d'
182
+ - formatHourColumn
183
+ The format of the hour column displayed in the week and day view.
184
+ Default value: (version 0.1-0.3) 'j', (version 0.4+) 'ha'
185
+ - calendarMode
186
+ The initial mode of the calendar.
187
+ Default value: 'month'
188
+
189
+ ```html
190
+ <calendar ... [calendarMode]="calendar.mode"></calendar>
191
+ ```
192
+
193
+ Version 1.0.x onwards
194
+
195
+ ```typescript
196
+ import { CalendarMode } from "ionic2-calendar";
197
+
198
+ calendar = {
199
+ mode: "week" as CalendarMode,
200
+ };
201
+ ```
202
+
203
+ Version 0.x
204
+
205
+ ```typescript
206
+ import { CalendarMode } from "ionic2-calendar/calendar";
207
+
208
+ calendar = {
209
+ mode: "week" as CalendarMode,
210
+ };
211
+ ```
212
+
213
+ - showEventDetail
214
+ If set to true, when selecting the date in the month view, the events happened on that day will be shown below.
215
+ Default value: true
216
+ - startingDayMonth
217
+ Control month view starting from which day.
218
+ Default value: 0 (Sunday)
219
+ - startingDayWeek
220
+ Control week view starting from which day.
221
+ Default value: 0 (Sunday)
222
+ - allDayLabel
223
+ The text displayed in the allDay column header of week and day view.
224
+ Default value: 'all day'
225
+ - noEventsLabel
226
+ The text displayed when there’s no event on the selected date in month view.
227
+ Default value: 'No Events'
228
+ - eventSource
229
+ The data source of the calendar, when the eventSource is set, the view will be updated accordingly.
230
+ Default value: null
231
+ The format of the eventSource is described in the [EventSource](#eventsource) section
232
+ - queryMode
233
+ 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
234
+ If queryMode is set to 'remote', when the range or mode is changed, the calendar will trigger a callback function rangeChanged.
235
+ 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.
236
+ Default value: 'local'
237
+ - step
238
+ 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.
239
+ Default value: 60
240
+
241
+ ```html
242
+ <calendar ... [step]="calendar.step"></calendar>
243
+ ```
244
+
245
+ ```typescript
246
+ import { Step } from "ionic2-calendar/calendar";
247
+
248
+ calendar = {
249
+ step: 30 as Step,
250
+ };
251
+ ```
252
+
253
+ - timeInterval (version >= 0.3)
254
+ 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.
255
+ The unit is minute. It should be the factor or multiple of 60, which means 60%timeInterval=0 or timeInterval%60=0.
256
+ Default value: 60
257
+
258
+ ```html
259
+ <calendar ... [timeInterval]="30"></calendar>
260
+ ```
261
+
262
+ - autoSelect
263
+ If set to true, the current calendar date will be auto selected when calendar is loaded or swiped in the month and week view.
264
+ Default value: true
265
+ - locale
266
+ The locale used to display text in the calendar.
267
+ Check [Localization](#localization) section for more details.
268
+ Default value: undefined (which means the local language)
269
+
270
+ ```html
271
+ <calendar ... [locale]="calendar.locale"></calendar>
272
+ ```
273
+
274
+ ```typescript
275
+ calendar = {
276
+ locale: "en-GB",
277
+ };
278
+ ```
279
+
280
+ - markDisabled
281
+ The callback function used to determine if the time should be marked as disabled.
282
+
283
+ ```html
284
+ <calendar ... [markDisabled]="markDisabled"></calendar>
285
+ ```
286
+
287
+ ```typescript
288
+ markDisabled = (date: Date) => {
289
+ var current = new Date();
290
+ return date < current;
291
+ };
292
+ ```
293
+
294
+ - dateFormatter
295
+ The custom date formatter to transform date to text.
296
+ If the custom date formatter is not set, the default Angular DatePipe is used.
297
+ The format method in dateFormatter is optional, if omitted, the default Angular DatePipe is used.
298
+
299
+ ```html
300
+ <calendar ... [dateFormatter]="calendar.dateFormatter"></calendar>
301
+ ```
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
+
334
+ - dir
335
+ If set to "rtl", the calendar supports RTL language. This feature is only supported in Ionic 2.3.0 version onwards.
336
+ Default value: ""
337
+
338
+ - scrollToHour
339
+ Make weekview and dayview scroll to the specific hour after entering to the new view.
340
+ Default value: 0
341
+
342
+ - preserveScrollPosition
343
+ If set to true, the previous/next views in weekview and dayview will also scroll to the same position as the current active view.
344
+ Default value: false
345
+
346
+ - lockSwipeToPrev
347
+ If set to true, swiping to previous view is disabled.
348
+ Default value: false
349
+
350
+ ```html
351
+ <calendar ... [lockSwipeToPrev]="lockSwipeToPrev"></calendar>
352
+ ```
353
+
354
+ ```typescript
355
+ onCurrentDateChanged(event:Date) {
356
+ var today = new Date();
357
+ today.setHours(0, 0, 0, 0);
358
+ event.setHours(0, 0, 0, 0);
359
+
360
+ if (this.calendar.mode === 'month') {
361
+ if (event.getFullYear() < today.getFullYear() || (event.getFullYear() === today.getFullYear() && event.getMonth() <= today.getMonth())) {
362
+ this.lockSwipeToPrev = true;
363
+ } else {
364
+ this.lockSwipeToPrev = false;
365
+ }
366
+ }
367
+ }
368
+ ```
369
+
370
+ - lockSwipeToNext (version 1.0.x onwards)
371
+ If set to true, swiping to next view is disabled.
372
+ Default value: false
373
+
374
+ ```html
375
+ <calendar ... [lockSwipeToNext]="lockSwipeToNext"></calendar>
376
+ ```
377
+
378
+ ```typescript
379
+ onCurrentDateChanged(event:Date) {
380
+ var today = new Date();
381
+ today.setHours(0, 0, 0, 0);
382
+ event.setHours(0, 0, 0, 0);
383
+
384
+ if (this.calendar.mode === 'month') {
385
+ if (event.getFullYear() > today.getFullYear() || (event.getFullYear() === today.getFullYear() && event.getMonth() >= today.getMonth())) {
386
+ this.lockSwipeToNext = true;
387
+ } else {
388
+ this.lockSwipeToNext = false;
389
+ }
390
+ }
391
+ }
392
+ ```
393
+
394
+ - lockSwipes
395
+ If set to true, swiping is disabled.
396
+ Default value: false
397
+
398
+ **Version 1.x**
399
+ _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.
400
+
401
+ ```html
402
+ <calendar ... [lockSwipes]="lockSwipes"></calendar>
403
+ ```
404
+
405
+ ```typescript
406
+ moveSlide() {
407
+ this.calendar.lockSwipes = false;
408
+ setTimeout(function() {
409
+ this.myCalendar.slideNext();
410
+ this.calendar.lockSwipes = true;
411
+ },100);
412
+ }
413
+ ```
414
+
415
+ **Version 0.x**
416
+ _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.
417
+
418
+ ```html
419
+ <calendar ... [lockSwipes]="lockSwipes"></calendar>
420
+ ```
421
+
422
+ ```typescript
423
+ ngAfterViewInit() {
424
+ var me = this;
425
+ setTimeout(function() {
426
+ me.lockSwipes = true;
427
+ },100);
428
+ }
429
+ ```
430
+
431
+ - startHour
432
+ Limit the weekview and dayview starts from which hour (0-23).
433
+ Default value: 0
434
+
435
+ ```html
436
+ <calendar ... startHour="9"></calendar>
437
+ ```
438
+
439
+ - endHour
440
+ Limit the weekview and dayview ends until which hour (1-24).
441
+ Default value: 24
442
+
443
+ ```html
444
+ <calendar ... endHour="19"></calendar>
445
+ ```
446
+
447
+ - sliderOptions
448
+ Options to pass to the underlying swiper instance. See https://swiperjs.com/swiper-api#parameters for valid options.
449
+
450
+ ```html
451
+ <calendar ... sliderOptions="sliderOptions"></calendar>
452
+ ```
453
+
454
+ ```typescript
455
+ options = {
456
+ spaceBetween: 10,
457
+ threshold: 50,
458
+ };
459
+ ```
460
+
461
+ - `dayviewShowCategoryView` (version: 2.4+)
462
+ Determines if show dayview with category
463
+ Type: `boolean`
464
+ Default value: `false`
465
+
466
+ - `dayviewCategorySource` (version: 2.4+)
467
+ 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.
468
+ Type: `Set<string>`
469
+ Default value: `null`
470
+
471
+ ```html
472
+ <calendar
473
+ ...
474
+ [dayviewCategorySource]="calendar.dayviewCategorySource"
475
+ ></calendar>
476
+ ```
477
+
478
+ ```typescript
479
+ calendar = {
480
+ dayviewCategorySource: new Set<string>(["Alice", "Bob", "Charlie"]),
481
+ };
482
+ ```
483
+
484
+ # Callback
485
+
486
+ - onCurrentDateChanged
487
+ The callback function triggered when the date that is currently viewed changes.
488
+
489
+ ```html
490
+ <calendar ... (onCurrentDateChanged)="onCurrentDateChanged($event)"></calendar>
491
+ ```
492
+
493
+ ```typescript
494
+ onCurrentChanged = (ev: Date) => {
495
+ console.log("Currently viewed date: " + ev);
496
+ };
497
+ ```
498
+
499
+ - onRangeChanged
500
+ The callback function triggered when the range or mode is changed if the **queryMode** is set to '**remote**'
501
+ The ev parameter contains two fields, startTime and endTime.
502
+
503
+ ```html
504
+ <calendar ... (onRangeChanged)="onRangeChanged($event)"></calendar>
505
+ ```
506
+
507
+ ```typescript
508
+ onRangeChanged = (ev: { startTime: Date; endTime: Date }) => {
509
+ Events.query(ev, (events) => {
510
+ this.eventSource = events;
511
+ });
512
+ };
513
+ ```
514
+
515
+ - onEventSelected
516
+ The callback function triggered when an event is clicked
517
+
518
+ ```html
519
+ <calendar ... (onEventSelected)="onEventSelected($event)"></calendar>
520
+ ```
521
+
522
+ ```typescript
523
+ onEventSelected = (event) => {
524
+ console.log(event.title);
525
+ };
526
+ ```
527
+
528
+ - onTimeSelected
529
+ The callback function triggered when a time slot is selected.
530
+ 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
531
+
532
+ ```html
533
+ <calendar ... (onTimeSelected)="onTimeSelected($event)"></calendar>
534
+ ```
535
+
536
+ ```typescript
537
+ onTimeSelected = (ev: {
538
+ selectedTime: Date;
539
+ events: any[];
540
+ disabled: boolean;
541
+ }) => {
542
+ console.log(
543
+ "Selected time: " +
544
+ ev.selectedTime +
545
+ ", hasEvents: " +
546
+ (ev.events !== undefined && ev.events.length !== 0) +
547
+ ", disabled: " +
548
+ ev.disabled,
549
+ );
550
+ };
551
+ ```
552
+
553
+ - onDayHeaderSelected
554
+ The callback function triggered when a day header is selected in week view.
555
+ 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
556
+
557
+ ```html
558
+ <calendar ... (onDayHeaderSelected)="onDayHeaderSelected($event)"></calendar>
559
+ ```
560
+
561
+ ```typescript
562
+ onDayHeaderSelected = (ev: {
563
+ selectedTime: Date;
564
+ events: any[];
565
+ disabled: boolean;
566
+ }) => {
567
+ console.log(
568
+ "Selected day: " +
569
+ ev.selectedTime +
570
+ ", hasEvents: " +
571
+ (ev.events !== undefined && ev.events.length !== 0) +
572
+ ", disabled: " +
573
+ ev.disabled,
574
+ );
575
+ };
576
+ ```
577
+
578
+ - onTitleChanged
579
+ The callback function triggered when the view title is changed
580
+
581
+ ```html
582
+ <calendar ... (onTitleChanged)="onViewTitleChanged($event)"></calendar>
583
+ ```
584
+
585
+ ```typescript
586
+ onViewTitleChanged = (title: string) => {
587
+ this.viewTitle = title;
588
+ };
589
+ ```
590
+
591
+ # View Customization Option
592
+
593
+ 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.
594
+
595
+ ## CSS Customization
596
+
597
+ The customized styles should be added in global.scss. Just adding in each components css file may not work due to the View Encapsulation.
598
+
599
+ - monthview-primary-with-event
600
+ The date that is in current month and having events
601
+
602
+ - monthview-secondary-with-event
603
+ The date that is in previous/next month and having events
604
+
605
+ - monthview-selected
606
+ The selected date
607
+
608
+ - monthview-current
609
+ The current date
610
+
611
+ - monthview-disabled
612
+ The disabled date
613
+
614
+ - weekview-with-event
615
+ The date having all day events, applied to the day header in week view
616
+
617
+ - weekview-current
618
+ The current date, applied to the day header in week view
619
+
620
+ - weekview-selected
621
+ The selected date, applied to the day header in week view
622
+
623
+ - weekview-allday-label
624
+ Applied to the all day label in week view
625
+
626
+ - dayview-allday-label
627
+ Applied to the all day label in day view
628
+
629
+ - calendar-hour-column
630
+ Applied to the hour column in both weekview and day view
631
+
632
+ - dayview-category-header (version: 2.4+)
633
+ Applied to the category section in day view
634
+
635
+ - dayview-category-header-item (version: 2.4+)
636
+ Applied to the category header item in day view
637
+
638
+ ## Template Customization
639
+
640
+ 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.
641
+
642
+ - monthviewDisplayEventTemplate
643
+ Type: TemplateRef\<IMonthViewDisplayEventTemplateContext\>
644
+ The template provides customized view for event displayed in the active monthview
645
+
646
+ ```html
647
+ <ng-template
648
+ #monthviewDisplayEventTemplate
649
+ let-view="view"
650
+ let-row="row"
651
+ let-col="col"
652
+ >
653
+ {{view.dates[row*7+col].label}}
654
+ </ng-template>
655
+
656
+ <calendar
657
+ ...
658
+ [monthviewDisplayEventTemplate]="monthviewDisplayEventTemplate"
659
+ ></calendar>
660
+ ```
661
+
662
+ - monthviewInactiveDisplayEventTemplate
663
+ Type: TemplateRef\<IMonthViewDisplayEventTemplateContext\>
664
+ The template provides customized view for event displayed in the inactive monthview
665
+
666
+ ```html
667
+ <ng-template
668
+ #monthviewInactiveDisplayEventTemplate
669
+ let-view="view"
670
+ let-row="row"
671
+ let-col="col"
672
+ >
673
+ {{view.dates[row*7+col].label}}
674
+ </ng-template>
675
+
676
+ <calendar
677
+ ...
678
+ [monthviewInactiveDisplayEventTemplate]="monthviewInactiveDisplayEventTemplate"
679
+ ></calendar>
680
+ ```
681
+
682
+ - monthviewEventDetailTemplate
683
+ Type: TemplateRef\<IMonthViewEventDetailTemplateContext\>
684
+ The template provides customized view for event detail section in the monthview
685
+
686
+ ```html
687
+ <ng-template
688
+ #monthviewEventDetailTemplate
689
+ let-showEventDetail="showEventDetail"
690
+ let-selectedDate="selectedDate"
691
+ let-noEventsLabel="noEventsLabel"
692
+ >
693
+ ...
694
+ </ng-template>
695
+
696
+ <calendar
697
+ ...
698
+ [monthviewEventDetailTemplate]="monthviewEventDetailTemplate"
699
+ ></calendar>
700
+ ```
701
+
702
+ - weekviewHeaderTemplate (version >= 0.4.5)
703
+ Type: TemplateRef\<IDisplayWeekViewHeader\>
704
+ The template provides customized view for day header in the weekview
705
+
706
+ ```html
707
+ <ng-template #weekviewHeaderTemplate let-viewDate="viewDate">
708
+ <div class="custom-day-header">{{ viewDate.dayHeader }}</div>
709
+ </ng-template>
710
+
711
+ <calendar ... [weekviewHeaderTemplate]="weekviewHeaderTemplate"></calendar>
712
+ ```
713
+
714
+ - weekviewAllDayEventTemplate
715
+ Type: TemplateRef\<IDisplayAllDayEvent\>
716
+ The template provides customized view for all day event in the weekview
717
+
718
+ ```html
719
+ <ng-template #weekviewAllDayEventTemplate let-displayEvent="displayEvent">
720
+ <div class="calendar-event-inner">{{displayEvent.event.title}}</div>
721
+ </ng-template>
722
+
723
+ <calendar
724
+ ...
725
+ [weekviewAllDayEventTemplate]="weekviewAllDayEventTemplate"
726
+ ></calendar>
727
+ ```
728
+
729
+ - weekviewNormalEventTemplate
730
+ Type: TemplateRef\<IDisplayEvent\>
731
+ The template provides customized view for normal event in the weekview
732
+
733
+ ```html
734
+ <ng-template #weekviewNormalEventTemplate let-displayEvent="displayEvent">
735
+ <div class="calendar-event-inner">{{displayEvent.event.title}}</div>
736
+ </ng-template>
737
+
738
+ <calendar
739
+ ...
740
+ [weekviewNormalEventTemplate]="weekviewNormalEventTemplate"
741
+ ></calendar>
742
+ ```
743
+
744
+ - dayviewCategoryItemTemplate (version: 2.4+)
745
+ The template provides customized view for category item with categoryId and categoryName in the day view
746
+
747
+ ```html
748
+ <ng-template #dayviewCategoryItemTemplate let-category="category">
749
+ {{ category.categoryName }}
750
+ </ng-template>
751
+
752
+ <calendar
753
+ ...
754
+ [dayviewCategoryItemTemplate]="dayviewCategoryItemTemplate"
755
+ ></calendar>
756
+ ```
757
+
758
+ - dayviewAllDayEventTemplate
759
+ Type: TemplateRef\<IDisplayAllDayEvent\>
760
+ The template provides customized view for all day event in the dayview
761
+
762
+ ```html
763
+ <ng-template #dayviewAllDayEventTemplate let-displayEvent="displayEvent">
764
+ <div class="calendar-event-inner">{{displayEvent.event.title}}</div>
765
+ </ng-template>
766
+
767
+ <calendar
768
+ ...
769
+ [dayviewAllDayEventTemplate]="dayviewAllDayEventTemplate"
770
+ ></calendar>
771
+ ```
772
+
773
+ - dayviewNormalEventTemplate
774
+ Type: TemplateRef\<IDisplayEvent\>
775
+ The template provides customized view for normal event in the dayview
776
+
777
+ ```html
778
+ <ng-template #dayviewNormalEventTemplate let-displayEvent="displayEvent">
779
+ <div class="calendar-event-inner">{{displayEvent.event.title}}</div>
780
+ </ng-template>
781
+
782
+ <calendar
783
+ ...
784
+ [dayviewNormalEventTemplate]="dayviewNormalEventTemplate"
785
+ ></calendar>
786
+ ```
787
+
788
+ - weekviewAllDayEventSectionTemplate (version >= 0.3)
789
+ Type: TemplateRef\<IWeekViewAllDayEventSectionTemplateContext\>
790
+ The template provides customized view for all day event section (table part) in the weekview
791
+
792
+ ```html
793
+ <ng-template
794
+ #weekviewAllDayEventSectionTemplate
795
+ let-day="day"
796
+ let-eventTemplate="eventTemplate"
797
+ >
798
+ <div
799
+ [ngClass]="{'calendar-event-wrap': day.events}"
800
+ *ngIf="day.events"
801
+ [ngStyle]="{height: 25*day.events.length+'px'}"
802
+ >
803
+ <div
804
+ *ngFor="let displayEvent of day.events"
805
+ class="calendar-event"
806
+ tappable
807
+ (click)="onEventSelected(displayEvent.event)"
808
+ [ngStyle]="{top: 25*displayEvent.position+'px', width: 100*(displayEvent.endIndex-displayEvent.startIndex)+'%', height: '25px'}"
809
+ >
810
+ <ng-template
811
+ [ngTemplateOutlet]="eventTemplate"
812
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}"
813
+ >
814
+ </ng-template>
815
+ </div>
816
+ </div>
817
+ </ng-template>
818
+
819
+ <calendar
820
+ ...
821
+ [weekviewAllDayEventSectionTemplate]="weekviewAllDayEventSectionTemplate"
822
+ ></calendar>
823
+ ```
824
+
825
+ - weekviewNormalEventSectionTemplate (version >= 0.3)
826
+ Type: TemplateRef\<IWeekViewNormalEventSectionTemplateContext\>
827
+ The template provides customized view for normal event section (table part) in the weekview
828
+
829
+ ```html
830
+ <ng-template
831
+ #weekviewNormalEventSectionTemplate
832
+ let-tm="tm"
833
+ let-hourParts="hourParts"
834
+ let-eventTemplate="eventTemplate"
835
+ >
836
+ <div [ngClass]="{'calendar-event-wrap': tm.events}" *ngIf="tm.events">
837
+ <div
838
+ *ngFor="let displayEvent of tm.events"
839
+ class="calendar-event"
840
+ tappable
841
+ (click)="onEventSelected(displayEvent.event)"
842
+ [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'}"
843
+ >
844
+ <ng-template
845
+ [ngTemplateOutlet]="eventTemplate"
846
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}"
847
+ >
848
+ </ng-template>
849
+ </div>
850
+ </div>
851
+ </ng-template>
852
+
853
+ <calendar
854
+ ...
855
+ [weekviewNormalEventSectionTemplate]="weekviewNormalEventSectionTemplate"
856
+ ></calendar>
857
+ ```
858
+
859
+ - dayviewAllDayEventSectionTemplate (version >= 0.3)
860
+ Type: TemplateRef\<IDayViewAllDayEventSectionTemplateContext\>
861
+ The template provides customized view for all day event section (table part) in the dayview
862
+
863
+ ```html
864
+ <ng-template
865
+ #dayviewAllDayEventSectionTemplate
866
+ let-allDayEvents="allDayEvents"
867
+ let-eventTemplate="eventTemplate"
868
+ >
869
+ <div
870
+ *ngFor="let displayEvent of allDayEvents; let eventIndex=index"
871
+ class="calendar-event"
872
+ tappable
873
+ (click)="onEventSelected(displayEvent.event)"
874
+ [ngStyle]="{top: 25*eventIndex+'px',width: '100%',height:'25px'}"
875
+ >
876
+ <ng-template
877
+ [ngTemplateOutlet]="eventTemplate"
878
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}"
879
+ >
880
+ </ng-template>
881
+ </div>
882
+ </ng-template>
883
+
884
+ <calendar
885
+ ...
886
+ [dayviewAllDayEventSectionTemplate]="dayviewAllDayEventSectionTemplate"
887
+ ></calendar>
888
+ ```
889
+
890
+ - dayviewNormalEventSectionTemplate (version >= 0.3)
891
+ Type: TemplateRef\<IDayViewNormalEventSectionTemplateContext\>
892
+ The template provides customized view for normal event section (table part) in the dayview
893
+
894
+ ```html
895
+ <ng-template
896
+ #dayviewNormalEventSectionTemplate
897
+ let-tm="tm"
898
+ let-hourParts="hourParts"
899
+ let-eventTemplate="eventTemplate"
900
+ >
901
+ <div [ngClass]="{'calendar-event-wrap': tm.events}" *ngIf="tm.events">
902
+ <div
903
+ *ngFor="let displayEvent of tm.events"
904
+ class="calendar-event"
905
+ tappable
906
+ (click)="onEventSelected(displayEvent.event)"
907
+ [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'}"
908
+ >
909
+ <ng-template
910
+ [ngTemplateOutlet]="eventTemplate"
911
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}"
912
+ >
913
+ </ng-template>
914
+ </div>
915
+ </div>
916
+ </ng-template>
917
+
918
+ <calendar
919
+ ...
920
+ [dayviewNormalEventSectionTemplate]="dayviewNormalEventSectionTemplate"
921
+ ></calendar>
922
+ ```
923
+
924
+ - weekviewInactiveAllDayEventSectionTemplate (version >= 0.5)
925
+ Type: TemplateRef\<IWeekViewAllDayEventSectionTemplateContext\>
926
+ The template provides customized view for all day event section (table part) in the inactive weekview
927
+
928
+ ```html
929
+ <ng-template
930
+ #weekviewInactiveAllDayEventSectionTemplate
931
+ let-day="day"
932
+ let-eventTemplate="eventTemplate"
933
+ >
934
+ <div
935
+ [ngClass]="{'calendar-event-wrap': day.events}"
936
+ *ngIf="day.events"
937
+ [ngStyle]="{height: 25*day.events.length+'px'}"
938
+ >
939
+ <div
940
+ *ngFor="let displayEvent of day.events"
941
+ class="calendar-event"
942
+ tappable
943
+ (click)="onEventSelected(displayEvent.event)"
944
+ [ngStyle]="{top: 25*displayEvent.position+'px', width: 100*(displayEvent.endIndex-displayEvent.startIndex)+'%', height: '25px'}"
945
+ >
946
+ <ng-template
947
+ [ngTemplateOutlet]="eventTemplate"
948
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}"
949
+ >
950
+ </ng-template>
951
+ </div>
952
+ </div>
953
+ </ng-template>
954
+
955
+        <calendar
956
+ ...
957
+ [weekviewInactiveAllDayEventSectionTemplate]="weekviewInactiveAllDayEventSectionTemplate"
958
+ ></calendar>
959
+ ```
960
+
961
+ - weekviewInactiveNormalEventSectionTemplate (version >= 0.5)
962
+ Type: TemplateRef\<IWeekViewNormalEventSectionTemplateContext\>
963
+ The template provides customized view for normal event section (table part) in the inactive weekview
964
+
965
+ ```html
966
+ <ng-template
967
+ #weekviewInactiveNormalEventSectionTemplate
968
+ let-tm="tm"
969
+ let-hourParts="hourParts"
970
+ let-eventTemplate="eventTemplate"
971
+ >
972
+ <div [ngClass]="{'calendar-event-wrap': tm.events}" *ngIf="tm.events">
973
+ <div
974
+ *ngFor="let displayEvent of tm.events"
975
+ class="calendar-event"
976
+ tappable
977
+ (click)="onEventSelected(displayEvent.event)"
978
+ [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'}"
979
+ >
980
+ <ng-template
981
+ [ngTemplateOutlet]="eventTemplate"
982
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}"
983
+ >
984
+ </ng-template>
985
+ </div>
986
+ </div>
987
+ </ng-template>
988
+
989
+        <calendar
990
+ ...
991
+ [weekviewInactiveNormalEventSectionTemplate]="weekviewInactiveNormalEventSectionTemplate"
992
+ ></calendar>
993
+ ```
994
+
995
+ - dayviewInactiveAllDayEventSectionTemplate (version >= 0.5)
996
+ Type: TemplateRef\<IDayViewAllDayEventSectionTemplateContext\>
997
+ The template provides customized view for all day event section (table part) in the inactive dayview
998
+
999
+ ```html
1000
+ <ng-template
1001
+ #dayviewInactiveAllDayEventSectionTemplate
1002
+ let-allDayEvents="allDayEvents"
1003
+ let-eventTemplate="eventTemplate"
1004
+ >
1005
+ <div
1006
+ *ngFor="let displayEvent of allDayEvents; let eventIndex=index"
1007
+ class="calendar-event"
1008
+ tappable
1009
+ (click)="onEventSelected(displayEvent.event)"
1010
+ [ngStyle]="{top: 25*eventIndex+'px',width: '100%',height:'25px'}"
1011
+ >
1012
+ <ng-template
1013
+ [ngTemplateOutlet]="eventTemplate"
1014
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}"
1015
+ >
1016
+ </ng-template>
1017
+ </div>
1018
+ </ng-template>
1019
+
1020
+        <calendar
1021
+ ...
1022
+ [dayviewInactiveAllDayEventSectionTemplate]="dayviewInactiveAllDayEventSectionTemplate"
1023
+ ></calendar>
1024
+ ```
1025
+
1026
+ - dayviewInactiveNormalEventSectionTemplate (version >= 0.5)
1027
+ Type: TemplateRef\<IDayViewNormalEventSectionTemplateContext\>
1028
+ The template provides customized view for normal event section (table part) in the inactive dayview
1029
+
1030
+ ```html
1031
+ <ng-template
1032
+ #dayviewInactiveNormalEventSectionTemplate
1033
+ let-tm="tm"
1034
+ let-hourParts="hourParts"
1035
+ let-eventTemplate="eventTemplate"
1036
+ >
1037
+ <div [ngClass]="{'calendar-event-wrap': tm.events}" *ngIf="tm.events">
1038
+ <div
1039
+ *ngFor="let displayEvent of tm.events"
1040
+ class="calendar-event"
1041
+ tappable
1042
+ (click)="onEventSelected(displayEvent.event)"
1043
+ [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'}"
1044
+ >
1045
+ <ng-template
1046
+ [ngTemplateOutlet]="eventTemplate"
1047
+ [ngTemplateOutletContext]="{displayEvent:displayEvent}"
1048
+ >
1049
+ </ng-template>
1050
+ </div>
1051
+ </div>
1052
+ </ng-template>
1053
+
1054
+        <calendar
1055
+ ...
1056
+ [dayviewInactiveNormalEventSectionTemplate]="dayviewInactiveNormalEventSectionTemplate"
1057
+ ></calendar>
1058
+ ```
1059
+
1060
+ # EventSource
1061
+
1062
+ EventSource is an array of event object which contains at least below fields:
1063
+
1064
+ - title
1065
+ Type: `string`
1066
+
1067
+ - startTime
1068
+ Type: `Date`
1069
+ 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.
1070
+ For example, if an allDay event starting from 2014-05-09, then startTime is
1071
+
1072
+ ```javascript
1073
+ var startTime = new Date(Date.UTC(2014, 4, 8));
1074
+ ```
1075
+
1076
+ - endTime
1077
+ Type: `Date`
1078
+ 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.
1079
+ For example, if an allDay event ending to 2014-05-10, then endTime is
1080
+
1081
+ ```javascript
1082
+ var endTime = new Date(Date.UTC(2014, 4, 9));
1083
+ ```
1084
+
1085
+ - allDay
1086
+ Type: `boolean`
1087
+ Indicates the event is allDay event or regular event
1088
+
1089
+ - category (optional)
1090
+ Type: `string`
1091
+ 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.
1092
+
1093
+ **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.
1094
+
1095
+ # Instance Methods
1096
+
1097
+ - loadEvents
1098
+ 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.
1099
+
1100
+ ```typescript
1101
+ import { CalendarComponent } from "ionic2-calendar";
1102
+
1103
+ @Component({
1104
+ selector: 'page-home',
1105
+ templateUrl: 'home.html'
1106
+ })
1107
+ export class HomePage {
1108
+ @ViewChild(CalendarComponent, null) myCalendar:CalendarComponent;
1109
+ eventSource;
1110
+
1111
+ loadEvents: function() {
1112
+ this.eventSource.push({
1113
+ title: 'test',
1114
+ startTime: startTime,
1115
+ endTime: endTime,
1116
+ allDay: false
1117
+ });
1118
+ this.myCalendar.loadEvents();
1119
+ }
1120
+ }
1121
+ ```
1122
+
1123
+ - slideNext (version >= 0.5)
1124
+ Slide the calendar to the next date range.
1125
+
1126
+ ```typescript
1127
+ import { CalendarComponent } from "ionic2-calendar";
1128
+
1129
+ @Component({
1130
+ selector: 'page-home',
1131
+ templateUrl: 'home.html'
1132
+ })
1133
+ export class HomePage {
1134
+ @ViewChild(CalendarComponent, null) myCalendar:CalendarComponent;
1135
+
1136
+ slideNext: function() {
1137
+ this.myCalendar.slideNext();
1138
+ }
1139
+ }
1140
+ ```
1141
+
1142
+ - slidePrev (version >= 0.5)
1143
+ Slide the calendar to the previous date range.
1144
+
1145
+ ```typescript
1146
+ import { CalendarComponent } from "ionic2-calendar";
1147
+
1148
+ @Component({
1149
+ selector: 'page-home',
1150
+ templateUrl: 'home.html'
1151
+ })
1152
+ export class HomePage {
1153
+ @ViewChild(CalendarComponent, null) myCalendar:CalendarComponent;
1154
+
1155
+ slidePrev: function() {
1156
+ this.myCalendar.slidePrev();
1157
+ }
1158
+ }
1159
+ ```
1160
+
1161
+ - update (version >= 0.6.5)
1162
+ Update the underlying slides.
1163
+
1164
+ ```typescript
1165
+ import { CalendarComponent } from "ionic2-calendar";
1166
+
1167
+ @Component({
1168
+ selector: 'page-home',
1169
+ templateUrl: 'home.html'
1170
+ })
1171
+ export class HomePage {
1172
+ @ViewChild(CalendarComponent, null) myCalendar:CalendarComponent;
1173
+
1174
+ slidePrev: function() {
1175
+ this.myCalendar.update();
1176
+ }
1177
+ }
1178
+ ```
1179
+
1180
+ # Localization
1181
+
1182
+ You could use _locale_ option to achieve the localization.
1183
+ If locale option is not specified, the calendar will use the LOCALE_ID set at the module level.
1184
+ 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.
1185
+ 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.
1186
+
1187
+ ```typescript
1188
+ import { NgModule, LOCALE_ID } from '@angular/core';
1189
+
1190
+ @NgModule({
1191
+
1192
+ providers: [
1193
+ { provide: LOCALE_ID, useValue: 'zh-CN' }
1194
+ ]
1195
+ })
1196
+ ```
1197
+
1198
+ 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.
1199
+
1200
+ ```typescript
1201
+ import { registerLocaleData } from "@angular/common";
1202
+ import localeZh from "@angular/common/locales/zh";
1203
+ registerLocaleData(localeZh);
1204
+ ```
1205
+
1206
+ If you want to change the locale dynamically, you should use _locale_ option instead of LOCALE_ID.
1207
+
1208
+ # Performance Tuning
1209
+
1210
+ 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.
1211
+
1212
+ ```html
1213
+ <calendar ... [dateFormatter]="calendar.dateFormatter"></calendar>
1214
+ ```
1215
+
1216
+ ```typescript
1217
+ calendar = {
1218
+ dateFormatter: {
1219
+ formatMonthViewDay: function (date: Date) {
1220
+ return date.getDate().toString();
1221
+ },
1222
+ },
1223
+ };
1224
+ ```
1225
+
1226
+ # Known issue (No longer exists in version 1.0.x)
1227
+
1228
+ This component updates the ion-slide dynamically so that only 3 looped slides are needed.
1229
+ 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.
1230
+ 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.
1231
+ Once the sliding is over, the slide will be forced to render the forth month.
1232
+
1233
+ # Common Questions
1234
+
1235
+ - Error: Cannot find module "intl"
1236
+ Answer: This calendar has dependency on 'Intl'. Run _npm install intl@1.2.5_ to install the dependency
1237
+
1238
+ - Error: Cannot read property 'getFullYear' of undefined
1239
+ Answer: If you bind currentDate like this: [currentDate]="calendar.currentDate". You need to assign calendar.currentDate a valid Date object
1240
+
1241
+ - How to switch the calendar to previous/next month programmatically?
1242
+ Answer: You can change currentDate to the date in previous/next month. You could also call the instance method slideNext/slidePrev.
1243
+
1244
+ - Error: Cannot read property 'dayHeaders' of undefined
1245
+ Answer: Take a look at the Localization section. For version 0.4.x+, you need to manually register the locale.
1246
+
1247
+ - Error: TypeError: event_1.startTime.getTime is not a function
1248
+ 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.
1249
+
1250
+ - Error: How to override css
1251
+ 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.
1252
+
1253
+ ```css
1254
+ .table-bordered[_ngcontent-jto-c5] {
1255
+ border: 1px solid #ddd !important;
1256
+ }
1257
+ ```