Cordova.file is not working

I’m calling cordova.file.dataDirectory and I keep getting the following error message:

TypeError: Cannot read property ‘dataDirectory’ of undefined

I’ve scoured Google for three hours looking for answers.

Here is a stack trace:
Here is the code where I call it:
Here is the main app module (unmodified after ionic start cmd):

I only share the last file because I have found mentions on Google of putting the call inside ionicPlatform.ready() function but the tutorial I’m following does not do it that way.

Thank you.

Did you install the Cordova file plugin? From the terminal in the root of your project:

ionic plugin add org.apache.cordova.file

Wow, thank you. That worked. I had run “cordova plugin add org.apache.cordova.file”. I did not know that I had to use “ionic” instead of"cordova". Is that true for all plugins? Thank you.

Yeah, I don’t know what the difference is, as I think the Ionic CLI is a wrapper for the Cordova CLI as far as plugins go. I just use the Ionic CLI all the time for consistency and just in case something is different - which it apparently is in this case.

same problem here on ios 7.1.2

cordova.file is undefined on ios, on android its working!

Any ideas?
I used this plugin: cordova plugin add cordova-plugin-file

I’m out of ideas after six hours of searching the web …

Did you guys fond a solution or workaround?

The same suddenly appeared on adnroid 4.4.4. The strange thing is that I can do console.log(cordova) and I see cordova.file which looks fine. But when I do console.log(cordova.file) one line below I get undefined.

Hi all, a quick follow-up on ‘cordova plugin add’ vs. ‘ionic plugin add’. Ionic CLI indeed wraps some cordova methods, but it also extends/fixes some things on it, e.g. by adding the plugin to the package.json. This might be useful when using ‘ionic state reset’ as it will take the package.json as base for plugin installation.