I’m new to Ionic / AngularJS and I’m trying to parse an json file with the Cordova plugin FileSystem in a service and return its content. I’ve downloaded the file with File-Transfer to the Library folder of the iOS app.
Something is wrong with my code, but I can’t figure it out. Any help is appreciated.
controllers.js
myApp.controller('MensaMenuCtrl', function($scope, LoadData) {
$scope.data = LoadData.all();
});
services.js
myApp.factory('LoadData', function() {
function onInitFs(fs) {
fs.root.getFile('data.json', {}, function(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
var json = this.result;
var obj = JSON.parse(json);
return obj;
};
reader.readAsText(file);
}, errorHandler);
}, errorHandler);
}
function errorHandler(e) {
alert('Error');
}
return {
all: function() {
return window.requestFileSystem(window.PERSISTENT, 1024*1024, onInitFs, errorHandler);
}
}
});
Error from the console
Error: 'undefined' is not a function (evaluating 'window.requestFileSystem(window.PERSISTENT, 1024*1024, onInitFs, errorHandler)')