Skip to content

window.plugins undefined #95

@bentaly

Description

@bentaly

Hi,

I am using ionic and want to save events to the native calendar.

Firstly, can this be done with your plugin? I'm under the assumption it can. if not, let me know and read no further.

I added your plugin on the command line with
ionic plugin add https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin.git

and then in my app call
var cal = window.plugins.calendar;
cal.createEventInteractively(title, location, notes, start, end, onSuccess, onError);

In the browser (which is the only place I can debug) window.plugins is undefined.

On the device it seems nothing happens.

Any idea what might be the issue?

Sorry to bother you, any help would be appreciated.

Ben

Activity

EddyVerbruggen

EddyVerbruggen commented on Sep 7, 2014

@EddyVerbruggen
Owner

Hi,

I don't use the Ionic CLI myself, but it as it's based on the Cordova CLI you could try this instead:

cordova plugin remove nl.x-services.plugins.calendar
cordova plugin add https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin
cordova prepare
bentaly

bentaly commented on Sep 8, 2014

@bentaly
Author

Thankyou so much, I will try this when I'm back, will let you know

bentaly

bentaly commented on Sep 10, 2014

@bentaly
Author

Unfortunately I tried it and the error on the device is

'undefined' is not an object (evaluating 'window.plugins.calendar')

Do you think this is something that should work with ionic CLI?

Thanks

samedii

samedii commented on Sep 11, 2014

@samedii
Contributor

Try waiting for 'deviceready'

document.addEventListener("deviceready", function() {
alert(window.plugins);
}, false);

bentaly

bentaly commented on Sep 11, 2014

@bentaly
Author

I added that, it still came through as undefined. I already had the

$ionicPlatform.ready(function(){
});

Which shows the plugins as undefined too.

I'm pretty sure the above method handles the 'deviceready' event anyway.

Have you heard of anyone using this successfully with Ionic?

carchrae

carchrae commented on Sep 16, 2014

@carchrae
bentaly

bentaly commented on Sep 17, 2014

@bentaly
Author

I have read that post, I dont really know what he's done differently, I know the plugin works, I have made a quick app and it works, i just dont know why it doesnt in my main app, there is not much structural difference, i will find out and post here.

carchrae

carchrae commented on Sep 17, 2014

@carchrae

Was the app that works in Ionic? I'm still trying to learn how/why ionic loads cordova plugins differently. Maybe it is something to do with the live reloading feature.

Have you looked at ng-cordova? This seemed like a good way to tie plugins into ionic. http://ionicframework.com/blog/ng-cordova/

bentaly

bentaly commented on Sep 17, 2014

@bentaly
Author

It was an Ionic app, just a single controller, with a method to call the calendar, it works fine.

I have looked at ng-cordova, alas there is no calendar support

carchrae

carchrae commented on Sep 17, 2014

@carchrae

why not add it? i'm curious if that would work.

https://github.com/driftyco/ng-cordova/blob/master/src/plugins/datepicker.js
https://github.com/driftyco/ng-cordova/blob/d59a5881ae84ec1ebe92dd5d82ae3c3662c7dc54/src/plugins/module.js#L42

the main reason that adding it via ng-cordova might be better is that i think/hope the initialization code timing is handled for you.

i want to try wrapping another plugin that does not seem work either - same issue of window.plugins being undefined.

i did wonder if trying an older version of ionic might help - if there have been some regressions or api changes.

bentaly

bentaly commented on Sep 17, 2014

@bentaly
Author

I imagine some issues on the timings would be added for you, I just dont think my app has the same issue.

Which plugin doesnt work for you?
have you tried making a simple seperate app to test just that functionality?

carchrae

carchrae commented on Sep 17, 2014

@carchrae

i've been trying to get http://ngcordova.com/docs/#BackgroundGeolocation working in ionic. and i'm wrong about wrapping it - it is already wrapped by ngCordova. i started off with a simple app first, but no luck. pretty annoying but I suspect it is something stupid i am doing or a version/regression issue. i'll dig into how these plugins are wrapped and perhaps that'll shed some light.

bentaly

bentaly commented on Sep 17, 2014

@bentaly
Author

good luck - let me know how you get on, ill share any joy I have

carchrae

carchrae commented on Sep 17, 2014

@carchrae

i also tried using that plugin directly, without wrapping. in both cases the window.plugins code was undefined. i did find an issue where the plugin author said that another plugin had polluted the namespace (i think the push plugin - not sure) with code like this if (!window.plugins) window.plugins = {} so wonder if that is what might be happening

bentaly

bentaly commented on Sep 17, 2014

@bentaly
Author

hmm, I'm not using any others apart from the default ionic ones, dont think that would be my issue

1 remaining item

EddyVerbruggen

EddyVerbruggen commented on Sep 17, 2014

@EddyVerbruggen
Owner

@bentaly cool, if you can, can you add an escaped version of the thing you had to add (for future reference)? Thx!

carchrae

carchrae commented on Sep 17, 2014

@carchrae

to what @EddyVerbruggen says - use backticks around the code sample. It is a shame that github does not handle that by default instead of dumping it.

EddyVerbruggen

EddyVerbruggen commented on Sep 17, 2014

@EddyVerbruggen
Owner

@carchrae +1 on that

bentaly

bentaly commented on Sep 18, 2014

@bentaly
Author

haha didn't notice it cut it out -

I simply had to add

<script src="cordova.js"></script>

Which is 404 during development but the script seems to be injected to the root at runtime when on a device.

GSD-Automatisering

GSD-Automatisering commented on Mar 12, 2015

@GSD-Automatisering

I have a problem on IOS no errors no succes all methods have been recognized but no items in calendar does someone have an idea ?

bentaly

bentaly commented on Mar 12, 2015

@bentaly
Author

is it in the:
$window.document.addEventListener('deviceready', function(){});
method?

GSD-Automatisering

GSD-Automatisering commented on Mar 12, 2015

@GSD-Automatisering

No its after Deviceready has been fired android version works well

ergencemir

ergencemir commented on Aug 14, 2018

@ergencemir

Hi @GSD-Automatisering ,
Did you resolve problem?

Junijoh

Junijoh commented on Jan 5, 2019

@Junijoh

Has anyone resolved the issue? I'm getting this error even though I load cordova.js at the beginning!

pointer

pointer commented on Jan 22, 2019

@pointer

Anyone??

thien1590

thien1590 commented on Apr 17, 2020

@thien1590

am here too soon :(

Marcel-Bich

Marcel-Bich commented on Jul 14, 2020

@Marcel-Bich

Have you tried window.onload in your index.html?
In some of my phonegap apps this helped out:

window.onload = function() {
	app.initialize()
}

And of course the holy grail in phonegap or cordova development:

phonegap platform rm YOURPLATFORM
phonegap platform add YOURPLATFORM
phonegap build YOURPLATFORM

This fixes almost every incomprehensible bugs for me.

pointer

pointer commented on Jul 14, 2020

@pointer
pumpkin-zbh

pumpkin-zbh commented on Jul 9, 2021

@pumpkin-zbh

(window as any).cordova.plugins.[pluginName]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @carchrae@EddyVerbruggen@samedii@GSD-Automatisering@bentaly

        Issue actions

          window.plugins undefined · Issue #95 · EddyVerbruggen/Calendar-PhoneGap-Plugin