当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

ion2-calendar

授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 陶烨赫
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

�� ion2-calendar

date

English is not my native language; please excuse typing errors.中文文档

  • Support date range.
  • Support multi date.
  • Support HTML components.
  • Disable weekdays or weekends.
  • Setting days event.
  • Setting localization.
  • Material design.

Support

  • ionic-angular ^3.0.0 2.x
  • @ionic/angular 4.0.0

Demo

live demo click me.

Usage

Installation

$ npm install ion2-calendar moment --save

Import module

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from '@ionic/angular';
import { MyApp } from './app.component';
...
import { CalendarModule } from 'ion2-calendar';

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

Change Defaults

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
...
import { CalendarModule } from "ion2-calendar";

@NgModule({
  declarations: [
    MyApp,
    ...
  ],
  imports: [
    IonicModule.forRoot(MyApp),
    // See CalendarComponentOptions for options
    CalendarModule.forRoot({
      doneLabel: 'Save',
      closeIcon: true
    })
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    ...
  ]
})
export class AppModule {}

Components Mode

Basic

<ion-calendar [(ngModel)]="date"
              (change)="onChange($event)"
              [type]="type"
              [format]="'YYYY-MM-DD'">
</ion-calendar>
import { Component } from '@angular/core';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  date: string;
  type: 'string'; // 'string' | 'js-date' | 'moment' | 'time' | 'object'
  constructor() { }

  onChange($event) {
    console.log($event);
  }
  ...
}

Date range

<ion-calendar [(ngModel)]="dateRange"
              [options]="optionsRange"
              [type]="type"
              [format]="'YYYY-MM-DD'">
</ion-calendar>
import { Component } from '@angular/core';
import { CalendarComponentOptions } from 'ion2-calendar';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  dateRange: { from: string; to: string; };
  type: 'string'; // 'string' | 'js-date' | 'moment' | 'time' | 'object'
  optionsRange: CalendarComponentOptions = {
    pickMode: 'range'
  };

  constructor() { }
  ...
}

Multi Date

<ion-calendar [(ngModel)]="dateMulti"
              [options]="optionsMulti"
              [type]="type"
              [format]="'YYYY-MM-DD'">
</ion-calendar>
import { Component } from '@angular/core';
import { CalendarComponentOptions } from 'ion2-calendar';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  dateMulti: string[];
  type: 'string'; // 'string' | 'js-date' | 'moment' | 'time' | 'object'
  optionsMulti: CalendarComponentOptions = {
    pickMode: 'multi'
  };

  constructor() { }
  ...
}

Input Properties

Name Type Default Description
options CalendarComponentOptions null options
format string 'YYYY-MM-DD' value format
type string 'string' value type
readonly boolean false readonly

Output Properties

Name Type Description
change EventEmitter event for model change
monthChange EventEmitter event for month change
select EventEmitter event for click day-button
selectStart EventEmitter event for click day-button
selectEnd EventEmitter event for click day-button

CalendarComponentOptions

Name Type Default Description
from Date new Date() start date
to Date 0 (Infinite) end date
color string 'primary' 'primary', 'secondary', 'danger', 'light', 'dark'
pickMode string single 'multi', 'range', 'single'
showToggleButtons boolean true show toggle buttons
showMonthPicker boolean true show month picker
monthPickerFormat Array ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'] month picker format
defaultTitle string '' default title in days
defaultSubtitle string '' default subtitle in days
disableWeeks Array [] week to be disabled (0-6)
monthFormat string 'MMM YYYY' month title format
weekdays Array ['S', 'M', 'T', 'W', 'T', 'F', 'S'] weeks text
weekStart number 0 (0 or 1) set week start day
daysConfig Array<DaysConfig> [] days configuration

Modal Mode

Basic

Import ion2-calendar in component controller.

import { Component } from '@angular/core';
import { ModalController } from '@ionic/angular';
import {
  CalendarModal,
  CalendarModalOptions,
  DayConfig,
  CalendarResult
} from 'ion2-calendar';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  constructor(public modalCtrl: ModalController) {}

  openCalendar() {
    const options: CalendarModalOptions = {
      title: 'BASIC'
    };

    const myCalendar = await this.modalCtrl.create({
      component: CalendarModal,
      componentProps: { options }
    });

    myCalendar.present();

    const event: any = await myCalendar.onDidDismiss();
    const date: CalendarResult = event.data;
    console.log(date);
  }
}

Date range

Set pickMode to 'range'.

openCalendar() {
  const options: CalendarModalOptions = {
    pickMode: 'range',
    title: 'RANGE'
  };

  const myCalendar = await this.modalCtrl.create({
    component: CalendarModal,
    componentProps: { options }
  });

  myCalendar.present();

  const event: any = await myCalendar.onDidDismiss();
  const date = event.data;
  const from: CalendarResult = date.from;
  const to: CalendarResult = date.to;

  console.log(date, from, to);
}

Multi Date

Set pickMode to 'multi'.

openCalendar() {
  const options = {
    pickMode: 'multi',
    title: 'MULTI'
  };

  const myCalendar = await this.modalCtrl.create({
    component: CalendarModal,
    componentProps: { options }
  });

  myCalendar.present();

  const event: any = await myCalendar.onDidDismiss();
  const date: CalendarResult = event.data;
  console.log(date);
}

Disable weeks

Use index eg: [0, 6] denote Sunday and Saturday.

openCalendar() {
  const options: CalendarModalOptions = {
    disableWeeks: [0, 6]
  };

  const myCalendar = await this.modalCtrl.create({
    component: CalendarModal,
    componentProps: { options }
  });

  myCalendar.present();

  const event: any = await myCalendar.onDidDismiss();
  const date: CalendarResult = event.data;
  console.log(date);
}

Localization

your root module

import { NgModule, LOCALE_ID } from '@angular/core';
...

@NgModule({
  ...
  providers: [{ provide: LOCALE_ID, useValue: "zh-CN" }]
})

...
openCalendar() {
  const options: CalendarModalOptions = {
    monthFormat: 'YYYY 年 MM 月 ',
    weekdays: ['天', '一', '二', '三', '四', '五', '六'],
    weekStart: 1,
    defaultDate: new Date()
  };

  const myCalendar = await this.modalCtrl.create({
    component: CalendarModal,
    componentProps: { options }
  });

  myCalendar.present();

  const event: any = await myCalendar.onDidDismiss();
  const date: CalendarResult = event.data;
  console.log(date);
}

Days config

Configure one day.

openCalendar() {
  let _daysConfig: DayConfig[] = [];
  for (let i = 0; i < 31; i++) {
    _daysConfig.push({
      date: new Date(2017, 0, i + 1),
      subTitle: `$${i + 1}`
    })
  }

  const options: CalendarModalOptions = {
    from: new Date(2017, 0, 1),
    to: new Date(2017, 11.1),
    daysConfig: _daysConfig
  };

  const myCalendar = await this.modalCtrl.create({
    component: CalendarModal,
    componentProps: { options }
  });

  myCalendar.present();

  const event: any = await myCalendar.onDidDismiss();
  const date: CalendarResult = event.data;
  console.log(date);
}

API

Modal Options

Name Type Default Description
from Date new Date() start date
to Date 0 (Infinite) end date
title string 'CALENDAR' title
color string 'primary' 'primary', 'secondary', 'danger', 'light', 'dark'
defaultScrollTo Date none let the view scroll to the default date
defaultDate Date none default date data, apply to single
defaultDates Array none default dates data, apply to multi
defaultDateRange { from: Date, to: Date } none default date-range data, apply to range
defaultTitle string '' default title in days
defaultSubtitle string '' default subtitle in days
cssClass string '' Additional classes for custom styles, separated by spaces.
canBackwardsSelected boolean false can backwards selected
pickMode string single 'multi', 'range', 'single'
disableWeeks Array [] week to be disabled (0-6)
closeLabel string CANCEL cancel button label
doneLabel string DONE done button label
clearLabel string null clear button label
closeIcon boolean false show cancel button icon
doneIcon boolean false show done button icon
monthFormat string 'MMM YYYY' month title format
weekdays Array ['S', 'M', 'T', 'W', 'T', 'F', 'S'] weeks text
weekStart number 0 (0 or 1) set week start day
daysConfig Array<DaysConfig> [] days configuration
step number 12 month load stepping interval to when scroll
defaultEndDateToStartDate boolean false makes the end date optional, will default it to the start

onDidDismiss Output { data } = event

pickMode Type
single { date: CalendarResult }
range { from: CalendarResult, to: CalendarResult }
multi Array<CalendarResult>

onDidDismiss Output { role } = event

Value Description
'cancel' dismissed by click the cancel button
'done' dismissed by click the done button
'backdrop' dismissed by click the backdrop

DaysConfig

Name Type Default Description
cssClass string '' separated by spaces
date Date required configured days
marked boolean false highlight color
disable boolean false disable
title string none displayed title eg: 'today'
subTitle string none subTitle subTitle eg: 'New Year\'s'

CalendarResult

Name Type
time number
unix number
dateObj Date
string string
years number
months number
date number

Thanks for reading

  • 在线实例 实例演示 默认 实例演示 每周第一天 实例演示 输入框插件 实例演示 HTML data 属性 实例演示 回调函数1 实例演示 回调函数2 使用方法  <div id="calendar"></div> 复制 <script>     $(function() {         $("#calendar").ionCalendar({             lang: 'zh-cn'

  • IT英语2-编程词汇编程英语词汇 A2A integration A2A整合  abstract 抽象的  abstract base class (ABC)抽象基类  abstract class 抽象类  abstraction 抽象、抽象物、抽象性  access 存取、访问  access level访问级别  access function 访问函数  account 账户  actio

  • OGNL---- 表达式语言  1. 访问bean属性: 直接通过属性链的形式进行设值与取值 <!-- 设置值 --> <s:form action="login"> <s:textfield name="user.username" lable="用户名" /> <s:textfield name="user.password" lable="密 码" /> <s:submit /> </

  • OGNL---- 表达式语言  1. 访问bean属性: 直接通过属性链的形式进行设值与取值 <!-- 设置值 --> <s:form action="login"> <s:textfield name="user.username" lable="用户名" /> <s:textfield name="user.password" lable="密 码" /> <s:submit /> </

 相关资料
  • 问题内容: 我的日历有问题。这是代码: 不能运行我的项目,因为在AndroidStudio显示错误,等…我得到nullPointException在模拟器运行时 它说 必须是以下之一:java.util.Calendar.DAY_OF_MONTHjava.util.Calendar.MONTH等… 我不明白此错误,因为它是其中之一 我有进口 对不起,我错过了它的初始化,但是还有另一个我想使用Cal

  • 问题内容: 我正在为要在应用程序中使用的日历设计xml格式,但无法将日历显示在 图形布局中 。 相反,我得到以下“错误”: 找不到以下类:-CalendarView(更改为android.widget.CalendarView,修复构建路径,编辑XML) 此项目的最低SDK版本为14,目标版本为15。 这是我的 XML 代码: 非常感激!谢谢! 问题答案: 您可能正在Android Target

  • 问题内容: 我只是想知道… 为什么我只有一个Calendar对象实例。有一个单例的原因吗? 我试图阅读文档,但他们没有提及为什么需要这样做。快速谷歌搜索没有给我任何答案。 问题答案: 日历不是单例,它是一个抽象类。该方法是一个Factory方法,它返回Calendar类的具体实现。 在Google上搜索java.util.Calendar源代码,您将看到它的工作方式。

  • 问题内容: 我想获得给定日期的一周的最后一个星期和第一个星期。例如,如果日期是2011年10月12日,那么我需要2011年10月10日(作为一周的开始日期)和2011年10月16日(作为一周的结束日期)的日期吗?有人知道如何使用日历获得这两个日期类(java.util.Calendar)非常感谢! 问题答案: 一些代码如何处理对象。我还应该提到joda时间库,因为它可以帮助您解决许多问题。 码

  • 问题内容: 我正在开发Java应用程序,并且有一个(位于中)。我可以轻松地使用以下代码将其更改为公历: 但是我需要在贾拉利日历中注明日期。我搜索了但没有找到任何好的图书馆。您知道可靠可靠的库来进行转换(或从中以Jalali格式创建日期)吗?我不需要实现或算法,因为此问题过于麻烦并且有很多规则,所以我需要一个可靠的解决方案 问题答案: 看看这个:https : //github.com/amirme

  • 问题内容: 我真的对方法调用的结果感到困惑,因为它返回了IST时间。 这是我使用的代码 我得到的答复是: 所以我尝试将默认的TimeZone更改为UTC,然后检查了一下,然后工作正常 结果: 我在这里想念什么吗? 问题答案: 该调用返回的。正是它将转换为的字符串,并且这种转换将使用您所用的默认时区。 您需要明确使用来在所需的时区中打印。 编辑:@Laurynas的礼貌,请考虑以下事项: