Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window.plugins undefined #95

Closed
bentaly opened this issue Sep 4, 2014 · 30 comments
Closed

window.plugins undefined #95

bentaly opened this issue Sep 4, 2014 · 30 comments

Comments

@bentaly
Copy link

@bentaly bentaly commented Sep 4, 2014

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

@EddyVerbruggen
Copy link
Owner

@EddyVerbruggen EddyVerbruggen commented Sep 7, 2014

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
Copy link
Author

@bentaly bentaly commented Sep 8, 2014

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

@bentaly
Copy link
Author

@bentaly bentaly commented Sep 10, 2014

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
Copy link
Contributor

@samedii samedii commented Sep 11, 2014

Try waiting for 'deviceready'

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

@bentaly
Copy link
Author

@bentaly bentaly commented Sep 11, 2014

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
Copy link

@carchrae carchrae commented Sep 16, 2014

@bentaly
Copy link
Author

@bentaly bentaly commented Sep 17, 2014

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
Copy link

@carchrae carchrae commented Sep 17, 2014

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
Copy link
Author

@bentaly bentaly commented Sep 17, 2014

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
Copy link

@carchrae carchrae commented Sep 17, 2014

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
Copy link
Author

@bentaly bentaly commented Sep 17, 2014

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
Copy link

@carchrae carchrae commented Sep 17, 2014

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
Copy link
Author

@bentaly bentaly commented Sep 17, 2014

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

@carchrae
Copy link

@carchrae carchrae commented Sep 17, 2014

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
Copy link
Author

@bentaly bentaly commented Sep 17, 2014

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

@bentaly
Copy link
Author

@bentaly bentaly commented Sep 17, 2014

Found my issue!

I had to add
<script src="cordova.js"></script>

to my html, the first script, even though I dont have the file. Very strange, havent come across this before but found it through process of elimination.

Thanks for the help Eddy

@EddyVerbruggen
Copy link
Owner

@EddyVerbruggen EddyVerbruggen commented Sep 17, 2014

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

@carchrae
Copy link

@carchrae carchrae commented Sep 17, 2014

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
Copy link
Owner

@EddyVerbruggen EddyVerbruggen commented Sep 17, 2014

@carchrae +1 on that

@bentaly
Copy link
Author

@bentaly bentaly commented Sep 18, 2014

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
Copy link

@GSD-Automatisering GSD-Automatisering commented Mar 12, 2015

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
Copy link
Author

@bentaly bentaly commented Mar 12, 2015

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

@GSD-Automatisering
Copy link

@GSD-Automatisering GSD-Automatisering commented Mar 12, 2015

No its after Deviceready has been fired android version works well

@ergencemir
Copy link

@ergencemir ergencemir commented Aug 14, 2018

Hi @GSD-Automatisering ,
Did you resolve problem?

@Junijoh
Copy link

@Junijoh Junijoh commented Jan 5, 2019

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

@pointer
Copy link

@pointer pointer commented Jan 22, 2019

Anyone??

@thien1590
Copy link

@thien1590 thien1590 commented Apr 17, 2020

am here too soon :(

@Marcel-Bich
Copy link

@Marcel-Bich Marcel-Bich commented Jul 14, 2020

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
Copy link

@pointer pointer commented Jul 14, 2020

@pumpkin-zbh
Copy link

@pumpkin-zbh pumpkin-zbh commented Jul 9, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests