我已经设置了一个AngularJS提供程序,在我的提供程序中,我正在尝试使用Cordova插件文件(http://ngcordova.com/docs/plugins/file/)。我已经设置它来获取$ cordovaFileProvider,但是当我尝试引用cordova.file.documentsDirectory时,我收到一个错误。
undefined不是对象(评估'cordova.file.documentsDirectory')
以下是代码示例。我在index.html文件中引用.provider('StateHelpersServ', ['$cordovaFileProvider', function ($cordovaFileProvider){
var prov = {};
prov.getFileData = function(key) {
// Check the platform
if (ionic.Platform.isIOS())
{
// Check if a file exists in a certain path, directory.
$cordovaFileProvider.checkFile(cordova.file.documentsDirectory, key + ".json")
.then(function (success) {
console.log("File Exist: " + success);
// Read a file
$cordovaFileProvider.readAsText(cordova.file.dataDirectory, key + ".json")
.then(function (success) {
console.log("ReadFile: " + success)
return success;
// success
}, function (error) {
// error
});
}, function (error) {
// File Doesn't Exist
console.log(error);
});
}
else if (ionic.Platform.isAndroid())
{
// Check if a file exists in a certain path, directory.
$cordovaFileProvider.checkFile(cordova.file.dataDirectory, key + ".json")
.then(function (success) {
console.log("File Exist: " + success);
// Read a file
$cordovaFileProvider.readAsText(cordova.file.dataDirectory, key + ".json")
.then(function (success) {
return success;
}, function (error) {
// error
});
}, function (error) {
console.log(error);
});
}
}
this.getFileData = prov.getFileData;
this.$get = [function() {
return prov;
}]
}])
并准备好设置离子平台。
List