Joseph Khella
Joseph Khella

Reputation: 715

Adding events to device calendar using Ionic framework

I'm creating a cross platform mobile app using Ionic framework and AngularJS In this app I need to get a date string and add it to the device's native calendar, is there a way to do so using only Ionic and AngularJS? and if there's no way to do so, can you tell me if there's a way doing so without them? Thank You !

Upvotes: 4

Views: 10373

Answers (1)

Ira Herman
Ira Herman

Reputation: 2826

Check out the Angular wrapper for Cordova calendar: http://ngcordova.com/docs/plugins/calendar/

Once you add ngCordova to your app.js and install the calendar plugin, you can inject $cordovaCalendar into your controller, then call it like this:

  $scope.createEvent = function(event){
    // Add to calendar interactively (vs silently):
    $cordovaCalendar.createEventInteractively({
      title: event.summary,
      location: event.location,
      notes: event.description,
      startDate: startsAt,
      endDate: endsAt
      // startDate: new Date(2015, 0, 6, 18, 30, 0, 0, 0),
      // endDate: new Date(2015, 1, 6, 12, 0, 0, 0, 0)
    }).then(function (result) {
      // success
    }, function (err) {
      // alert('Oops, something went wrong');
    });
  }

Upvotes: 7

Related Questions