How to ensure code runs after device is ready?


So I’m trying to access the filesystem through Cordova’s native file interface, inside of a service that’s part of my Ionic app.
I tried following the example here, but according to debug information cordova.file is undefined. Is there a proper way to access the cordova object from within Ionic/Angular code? Is this a configuration error?

EDIT: I’m testing this both in browser and in an emulated Android device.

So I’ve discovered the problem lies with the fact that there’s no guarantee that code will run before the device is ready. Is there an elegant way to make sure my code doesn’t execute until the deviceready event fires?




Ah, that does the trick. Thanks.