百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
I

Ionic2-Calendar

> 编程语言
开源

基于Ionic框架的日历组件

389 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

基于Ionic框架的日历组件

Ionic-Calendar directive

Ionic calendar directive
ionic2-calendar ionic8-calendar

Table of Contents

  1. Demo
  2. Dependency
  3. Usage
  4. Options
  5. Callback
  6. View Customization Option
  7. EventSource
  8. Performance Tuning
  9. Common Questions

Demo

Version 2.0
https://stackblitz.com/edit/ionic-calendar-demo-2-2?file=src%2Fapp%2Fexample.component.html
Version 1.0
https://stackblitz.com/edit/ionic-calendar-demo-1-0?file=src%2Fapp%2Fexample.component.html
Version 0.x
https://stackblitz.com/edit/ionic-calendar-demo?file=pages%2Fhome%2Fhome.html

Dependency

Calendar Version Ionic Version Angular Version Swiper Version
2.8.x >=8.0.0 >=20.0.0 >=12.0.0
2.7.x >=8.0.0 >=20.0.0 >=11.0.0
2.6.x >=8.0.0 >=19.0.0 >=11.0.0
2.5.x >=8.0.0 >=18.0.0 >=11.0.0
2.4.x >=7.0.0 >=17.0.0 >=11.0.0
2.3.x >=7.0.0 >=17.0.0 >=11.0.0
2.2.x >=7.0.0 >=1s7.0.0 >=10.1.0
2.1.x >=7.0.0 >=16.0.0 >=10.1.0
2.0.x >=7.0.0 >=16.0.0 [8.4.6, 9.0.0)
1.0.x >=6.1.9 >=15.1.2 [8.4.6, 9.0.0)
0.6.x >=5.1.0 >=9.1.0
0.5.x >=4.0.0-rc.1
0.4.x >=3.9.2
0.3.x >=3.1.1
0.2.9+ >=2.3.0
0.2.x 2.0.0-rc.5
0.1.x [2.0.0-rc.1, 2.0.0-rc.4]

version 0.2-0.4 has below dependency:
intl 1.2.5, due to issue https://github.com/angular/angular/issues/3333

Usage

1. Install Calendar Dependency

npm install ionic2-calendar --save

version 1.0.x onwards

version 1.0.x is also published as Ionic6-Calendar package name. So could also run
npm install ionic6-calendar --save
version 2.0.+ is also published as Ionic7-Calendar package name. So could also run
npm install ionic7-calendar --save
version 2.5.+ is also published as Ionic8-Calendar package name. So could also run
npm install ionic8-calendar --save

NOTE: Starting from Version 1.0.x, the underlying implementaion is based on Swiper instead of IonSlides, so also needs to install Swiper dependency.

  • Install swiper dependency
    npm install swiper --save

  • Import swiper css in global.scss

@import 'swiper/css';

2. Import the Calendar module

If using version 1.0.x, could use both ionic2-calendar or ionic6-calendar, ionic7-calendar, ionic8-calendar.

  • version 0.5.x onwards
typescript
import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from '@ionic/angular';
import { MyApp } from './app/app.component';
import { NgCalendarModule  } from 'ionic2-calendar';

@NgModule({
    declarations: [
        MyApp
    ],
    imports: [
        NgCalendarModule,
        IonicModule.forRoot(MyApp)
    ],
    bootstrap: [IonicApp],
    entryComponents: [
        MyApp
    ]
})
export class AppModule {}
  • version 0.1.x - 0.4.x
typescript
import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app/app.component';
import { NgCalendarModule  } from 'ionic2-calendar';

@NgModule({
    declarations: [
        MyApp
    ],
    imports: [
        NgCalendarModule,
        IonicModule.forRoot(MyApp)
    ],
    bootstrap: [IonicApp],
    entryComponents: [
        MyApp
    ]
})
export class AppModule {}

If you are using PageModule, you need to import the NgCalendarModule in your page module

typescript
import { NgCalendarModule  } from 'ionic2-calendar';

@NgModule({
  declarations: [
    MyPage
  ],
  imports: [
    IonicPageModule.forChild(MyPage),
    NgCalendarModule
  ],
  entryComponents: [
    MyPage
  ]
})
export class MyPageModule {}

3. Add the directive in the html page

xml
            
    

Options

  • formatDay
    The format of the date displayed in the month view.
    Default value: 'dd'
  • formatDayHeader
    The format of the header displayed in the month view.
    Default value: 'EEE'
  • formatDayTitle
    The format of the title displayed in the day view.
    Default value: 'MMMM dd, yyyy'
  • formatWeekTitle
    The format of the title displayed in the week view.
    Default value: (version 0.1-0.3) 'MMMM yyyy, Week $n', (version 0.4+) 'MMMM yyyy, 'Week' w'
  • formatMonthTitle
    The format of the title displayed in the month view.
    Default value: 'MMMM yyyy'
  • formatWeekViewDayHeader
    The format of the header displayed in the week view.
    Default value: 'EEE d'
  • formatHourColumn
    The format of the hour column displayed in the week and day view.
    Default value: (version 0.1-0.3) 'j', (version 0.4+) 'ha'
  • calendarMode
    The initial mode of the calendar.
    Default value: 'month'
xml
        

Version 1.0.x onwards

typescript
    import { CalendarMode } from 'ionic2-calendar';

    calendar = {
        mode: 'week' as CalendarMode
    };

Version 0.x

typescript
    import { CalendarMode } from 'ionic2-calendar/calendar';

    calendar = {
        mode: 'week' as CalendarMode
    };
  • showEventDetail
    If set to true, when selecting the date in the month view, the events happened on that day will be shown below.
    Default value: true
  • startingDayMonth
    Control month view starting from which day.
    Default value: 0 (Sunday)
  • startingDayWeek
    Control week view starting from which day.
    Default value: 0 (Sunday)
  • allDayLabel
    The text displayed in the allDay column header of week and day view.
    Default value: 'all day'
  • noEventsLabel
    The text displayed when there’s no event on the selected date in month view.
    Default value: 'No Events'
  • eventSource
    The data source of the calendar, when the eventSource is set, the view will be updated accordingly.
    Default value: null
    The format of the eventSource is described in the EventSource section
  • queryMode
    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
    If queryMode is set to 'remote', when the range or mode is changed, the calendar will trigger a callback function rangeChanged.
    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.
    Default value: 'local'
  • step
    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.
    Default value: 60
xml
    
typescript
    import { Step } from 'ionic2-calendar/calendar';

    calendar = {
        step: 30 as Step
    };
  • timeInterval (version >= 0.3)
    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. The unit is minute. It should be the factor or multiple of 60, which means 60%timeInterval=0 or timeInterval%60=0.
    Default value: 60
xml
    
  • autoSelect
    If set to true, the current calendar date will be auto selected when calendar is loaded or swiped in the month and week view.
    Default value: true
  • locale
    The locale used to display text in the calendar.
    Check Localization section for more details.
    Default value: undefined (which means the local language)
xml
    
typescript
    calendar = {
        locale: 'en-GB'
    };
  • markDisabled
    The callback function used to determine if the time should be marked as disabled.
xml
    
typescript
    markDisabled = (date: Date) => {
        var current = new Date();
        return date 
…
  • dir
    If set to "rtl", the calendar supports RTL language. This feature is only supported in Ionic 2.3.0 version onwards.
    Default value: ""

  • scrollToHour
    Make weekview and dayview scroll to the specific hour after entering to the new view.
    Default value: 0

  • preserveScrollPosition
    If set to true, the previous/next views in weekview and dayview will also scroll to the same position as the current active view.
    Default value: false

  • lockSwipeToPrev
    If set to true, swiping to previous view is disabled.
    Default value: false

xml
    
typescript
    onCurrentDateChanged(event:Date) {
        var today = new Date();
        today.setHours(0, 0, 0, 0);
        event.setHours(0, 0, 0, 0);

        if (this.calendar.mode === 'month') {
            if (event.getFullYear() 
typescript
    onCurrentDateChanged(event:Date) {
        var today = new Date();
        today.setHours(0, 0, 0, 0);
        event.setHours(0, 0, 0, 0);

        if (this.calendar.mode === 'month') {
            if (event.getFullYear() > today.getFullYear() || (event.getFullYear() === today.getFullYear() && event.getMonth() >= today.getMonth())) {
                this.lockSwipeToNext = true;
            } else {
                this.lockSwipeToNext = false;
            }
        }
    }
  • lockSwipes
    If set to true, swiping is disabled.
    Default value: false

Version 1.x
Note: Since swiping is disabled, you could set currentDate or call slideToPrev/slideToNext method to move the calendar to previous/next view. You need to first set the lockSwipes to false, move the slide, then set it back.

xml
    
typescript
    moveSlide() {
        this.calendar.lockSwipes = false;
        setTimeout(function() {
            this.myCalendar.slideNext();
            this.calendar.lockSwipes = true;
        },100);
    }

Version 0.x
Note: Since swiping is disabled, you could set currentDate or call slideToPrev/slideToNext method 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.

xml
    
typescript
    ngAfterViewInit() {
        var me = this;
        setTimeout(function() {
            me.lockSwipes = true;
        },100);
    }
  • startHour
    Limit the weekview and dayview starts from which hour (0-23).
    Default value: 0
xml
    
  • endHour
    Limit the weekview and dayview ends until which hour (1-24).
    Default value: 24
xml
    
  • sliderOptions
    Options to pass to the underlying swiper instance. See https://swiperjs.com/swiper-api#parameters for valid options.
xml
    
typescript
    options = {
        spaceBetween: 10,
        threshold: 50
    };
  • dayviewShowCategoryView (version: 2.4+)
    Determines if show dayview with category
    Type: boolean
    Default value: false

  • dayviewCategorySource (version: 2.4+)
    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.
    Type: Set
    Default value: null

xml
    
typescript
    calendar = {
        dayviewCategorySource: new Set(['Alice', 'Bob', 'Charlie'])
    };

Callback

  • onCurrentDateChanged
    The callback function triggered when the date that is currently viewed changes.
xml
    
typescript
    onCurrentChanged = (ev: Date) => {
        console.log('Currently viewed date: ' + ev);
    };
  • onRangeChanged
    The callback function triggered when the range or mode is changed if the queryMode is set to 'remote'
    The ev parameter contains two fields, startTime and endTime.
xml

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptcalendarionicionic2ionic3

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言