基于Ionic框架的日历组件
Ionic calendar directive
ionic2-calendar
ionic8-calendar
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
| 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
npm install ionic2-calendar --save
version 1.0.x is also published as Ionic6-Calendar package name. So could also runnpm install ionic6-calendar --save
version 2.0.+ is also published as Ionic7-Calendar package name. So could also runnpm install ionic7-calendar --save
version 2.5.+ is also published as Ionic8-Calendar package name. So could also runnpm 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 dependencynpm install swiper --save
Import swiper css in global.scss
@import 'swiper/css';If using version 1.0.x, could use both ionic2-calendar or ionic6-calendar, ionic7-calendar, ionic8-calendar.
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 {}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
import { NgCalendarModule } from 'ionic2-calendar';
@NgModule({
declarations: [
MyPage
],
imports: [
IonicPageModule.forChild(MyPage),
NgCalendarModule
],
entryComponents: [
MyPage
]
})
export class MyPageModule {}
Version 1.0.x onwards
import { CalendarMode } from 'ionic2-calendar';
calendar = {
mode: 'week' as CalendarMode
};Version 0.x
import { CalendarMode } from 'ionic2-calendar/calendar';
calendar = {
mode: 'week' as CalendarMode
}; import { Step } from 'ionic2-calendar/calendar';
calendar = {
step: 30 as Step
}; calendar = {
locale: 'en-GB'
}; 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
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() 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;
}
}
}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.
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.
ngAfterViewInit() {
var me = this;
setTimeout(function() {
me.lockSwipes = true;
},100);
} 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
calendar = {
dayviewCategorySource: new Set(['Alice', 'Bob', 'Charlie'])
}; onCurrentChanged = (ev: Date) => {
console.log('Currently viewed date: ' + ev);
};暂无开放 Issues,或尚未同步最近议题。