安装插件
ionic cordova plugin add cordova-plugin-calendar
npm install --save @ionic-native/calendar
*在app.module.ts中引入calendar
<script type="text/javascript" src="js/Calendar.js"></script>
html编码
<ion-content>
<h2>Calendar</h2>
<button (click)="getcalender()" ion-button full>calender</button>
</ion-content>
ts编码
引入import { Calendar } from '@ionic-native/calendar';
构造
constructor(public navCtrl: NavController,
private calendar : Calendar) {
}
//创建并打开
getcalender(){
this.calendar.createCalendar('MyCalendar').then(
(msg) => { console.log(msg);},
(err) => { console.log(err);}
);
this.calendar.openCalendar(new Date()).then(
(msg) => { console.log(msg);},
(err) => { console.log(err);}
);
}
根据官网示例的代码,只能创建日历,如果不执行openCalendar()方法,并不会看到你创建的日历。