Error - ngcordova - $cordovaFile - Cannot call method 'then' of undefined


Hello, I am using ngCordova - $cordovaFile to create a directory and to save some images.
I am getting error saying - Cannot call method ‘then’ of undefined… when trying to call $cordovaFile.createDir.

$cordovaFile.createDir("adExpress", true).then(function (result) {
    }, function (err) {

When I run above code I am getting error saying -TypeError: Cannot call method ‘then’ of undefined.

Can someone explain what is issue here?


Have you injected the $cordovaFile module?


Yes. Here is my controller

.controller('mediaController', function ($stateParams,$cordovaCamera, $cordovaFile,  ) {
 function getPicture(sourceType) {              
$cordovaFile.createDir("adExpress", false).then(function (result) {
        }, function (err) {

I am not understanding why I am seeing this error. While debug I am seeing proper $cordovaFile object.


Any input on this please?


Just curious, how do you have ng-codova/cordova loading? What order is your script tags?


Here is How I am loading my ng-cordova/cordova.

 <script src="cordova.js"></script>
    <script src="lib/ng-cordova.js"></script>

FYI, I am able to successfully work with $cordovaCamera. I am facing problem with $cordovaFile.


Can some one help me with this?

From where exactly I should download ng-cordova.js? I tried from this -


Same problem. I have access to the object but the callback doesn’t seem to fire - this is for the upload method.


ng-cordova should be before cordova.js, as per our documentation…

That npm package isn’t an official cordova, so you should be downloading the js file from the github page


Apologies I miscommunicated, here is my script loading.

 <script src="lib/ng-cordova.js"></script>
<script src="cordova.js"></script>

Still I am having the same problem. Not sure How to fix this. still looking for any fix.


I met the same problem. I modifying createDir method within ng-cordova.js. like this:

createDir: function (dir, replaceBOOL) {
    var q = $q.defer();
        function (filesystem) {
            filesystem.root.getDirectory(dir, {
                create: true,
                exclusive: replaceBOOL
            function () {
            function () {
    return q.promise;


It’s Solved.

If you want to know more details.I suggest you look at this:AngularJS API $q
I hope this can help you.