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) {
alert(result);
}, function (err) {
alert(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?
tobbe
July 3, 2014, 1:38pm
2
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) {
console.log(result);
}, function (err) {
console.log(result);
});
}
}
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 - https://www.npmjs.org/package/generator-ng-cordova
blox
July 6, 2014, 5:36am
8
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…
http://ngcordova.com/docs/
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();
getFilesystem().then(
function (filesystem) {
filesystem.root.getDirectory(dir, {
create: true,
exclusive: replaceBOOL
},
function () {
q.resolve();
},
function () {
q.reject();
});
}
);
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.