ngCordova File issue

Hello guys, i am trying to create a file using the ngCordovaFile plugin. But I am facing this error on my browser:

ReferenceError: cordova is not defined

Here is my code

$cordovaFile.createFile(cordova.file.dataDirectory, "session.txt", true)
  .then(function (success) {
    // success
    console.log('Session OK');
  }, function (error) {
    // error
    alert(JSON.stringify(err));
  });

please help !!

I have tested it on a physical device it still won’t work !!! :triumph:

What the alert saying for an error?

Well @mhartington when i lunch my app in the ionic browser simulator I have in console this message :

ReferenceError: cordova is not defined
at new <anonymous> (controllers.js:11)
at invoke (ionic.bundle.js:11994)
at Object.instantiate (ionic.bundle.js:12002)
at ionic.bundle.js:16255
at IonicModule.controller.self.appendViewElement (ionic.bundle.js:47320)
at Object.IonicModule.factory.ionicViewSwitcher.create.switcher.render (ionic.bundle.js:45864)
at Object.IonicModule.factory.ionicViewSwitcher.create.switcher.init (ionic.bundle.js:45784)
at IonicModule.controller.self.render (ionic.bundle.js:47225)
at IonicModule.controller.self.register (ionic.bundle.js:47181)
at updateView (ionic.bundle.js:50834)

and when I build up the app a run it on my device, the build success but the app will not stat i have just a blank sceen

Do you have cordova included in your index.html?

Yes just before the cordova.js as asked in the doc. the ngCordova works well with other plugins like toast a social sharing but only File storage fails.

Have you wrapped it in a device ready event?

$ionicPlatform.ready(function(){

});

No I think it’s the problem! Can you give me a correct example please?

@mhartington i’ve try to wrapped it in a device ready, same problem.

Hi @rickdana I’m afraid I updated the docs without creating a new release. The latest changes are in the master and should be working:

bower install ngCordova#master

1 Like

@pbernasconi Thank you dude ! Ijust downloaded the ngCordova#master but nothing change !

Did you install the plugin

yes the plugin is install !

Have you set your file directory for ‘cordova. file.dataDirectory’ ?

See this post on stackoverflow.com: http://stackoverflow.com/a/27524511/960514