Cordova.file undefined in factory

cordova.file.externalDataDirectory
This line when included in controller works normally but when I include it in a factory, the app does not open. There is only a white screen.
The error I am getting from Logcat is:

D/CordovaLog( 4176): file:///android_asset/www/lib/ionic/js/ionic.bundle.js: Line 19387 : TypeError: Cannot read property 'externalDataDirectory' of undefined

Apparently, cordova.file remains undefined in a factory even when window.cordova is defined. Any ideas why this must be happening?

I am testing out on Android.

The issue is resolved. Apparently cordova.file was being called before being initiated. I put it in another function and called that function and it started working fine.

1 Like

Something to keep in mind for all cordova plugins is to wrap them in a device ready function.

$ionicPlatform.ready(function() {
   // Any cordova plugins need to be fired in here
  });
3 Likes

This actually solves most of the issues.