Cordova is undefined

Hello all. I’m trying to get the file plugin working; well, ngCordova working in general. I’m having some problems… When running just a simple writeFile execution in the .run function of my module, I get a ReferenceError in my browser that cordova is undefined in my javascript. I included ng-cordova.js, I installed the app I wanted, etc.

I thought, hey, maybe it’s because it’s Cordova is running in the browser; but I built it to Android and ran it there and it still didn’t produce the result.

my code:

var app = angular.module('starter', ['ionic', 'ngCordova'])

.run(function($ionicPlatform, $cordovaFile) {
    $ionicPlatform.ready(function() {
      $cordovaFile.writeFile(cordova.file.dataDirectory, "file.txt", "text", true)
       .then(function (success) {
         // success
       }, function (error) {
         // error

(the cordova.file.dataDirectory cordova is undefined)

Any ideas to get this working?

Okay, so I found the problem: the emulator I’m using only runs with the android on an “external sd card,” so as such I had to change the cordova.file.dataDirectory to cordova.file.externalDataDirectory, and then I could find the file. Cordova is indeed undefined because it was running in the browser.

Now, my next challenge: async!