EddyVerbruggen / Calendar-PhoneGap-Plugin

:date: Cordova plugin to Create, Change, Delete and Find Events in the native Calendar
773 stars 402 forks source link

cannot read property calendar of undefined #246

Open santoshcsdev opened 8 years ago

santoshcsdev commented 8 years ago

Hi I am building a android app using ionic framework and angular JS.

I need to add a calendar event in my app ,when i run my app i am getting the issue "cannot read property calendar of undefined "

here are my .js codes //my app.js code // 'starter.services' is found in services.js // 'starter.controllers' is found in controllers.js angular.module('starter', ['ionic', 'starter.controllers','ngCordova'])

.run(function($ionicPlatform) { $ionicPlatform.ready(function() { // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard // for form inputs) if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); cordova.plugins.Keyboard.disableScroll(true);

}
if (window.StatusBar) {
  // org.apache.cordova.statusbar required
  StatusBar.styleLightContent();
}

}); }) .config(function($stateProvider, $urlRouterProvider) { $stateProvider .state('home', { url: '/home', templateUrl: 'templates/home.html', controller: 'HomeCtrl'

}) .state('login', { url: '/login', templateUrl: 'templates/login.html', controller: 'LoginCtrl' }) .state('register', { url: '/register', templateUrl: 'templates/register.html', controller: 'RegisterCtrl' })

.state('calendarevent', { url: '/calendarevent', templateUrl: 'templates/calendarevent.html', controller: 'CalendarCtrl'

});

//my controller.js code angular.module('starter.controllers', ['starter.services']){ .controller("CalendarCtrl", function($scope, $cordovaCalendar,calendarService) {

$scope.createEvent = function() {
    $cordovaCalendar.createEvent({
        title: 'Space Race',
        location: 'The Moon',
        notes: 'Bring sandwiches',
        startDate: new Date(2015, 0, 15, 18, 30, 0, 0, 0),
        endDate: new Date(2015, 1, 17, 12, 0, 0, 0, 0)
    }).then(function (result) {
        console.log("Event created successfully");
    }, function (err) {
        console.error("There was an error: " + err);
    });
}

});

//I am using templates in ionic and the html code is

Calendar Event

/////////////

I have already installed cordova camera plugin using below command

cordova plugin add https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin.git

please suggest me in fixing my code. Thanks

EddyVerbruggen commented 8 years ago

Hard to say with only bits and pieces of JS flying around.. did you check:

pablomaurer commented 8 years ago

please reformat you code, so it's readable... I wouldn't look at this issue like that.

will-russell commented 6 years ago

I am also getting this issue;

Discovered plugin "cordova-plugin-calendar" in config.xml. Adding it to the project
Installing "cordova-plugin-calendar" for android
Adding cordova-plugin-calendar to package.json
Saved plugin info for "cordova-plugin-calendar" to config.xml

Attempting to access window.plugins.calendar to perform anything (getCreateCalendarOptions() for example) fails with "Uncaught TypeError: Cannot read property 'calendar' of undefined" when remotely debugging the app on Chrome 68 (running the app-debug.apk from Android Studio on a Android 6.0 device through USB).

I am using cordova-android version 7.1.1; any additional information or things I should try, please let me know!

Any updates or thoughts?

will-russell commented 6 years ago

Some additional info:

Because of this, it appears that this script is not being run by Cordova - is there a way to determine why not?