I added two alert () "SUCCESS A" and "SUCCESS B "
it displays first "SUCCESS B" empty.
and "SUCCESS A" with [{"id":"1","name":"ABC"}, {"id":"2","name":"DEF"}]
var items = [];
app.service('itemProvider', function($ionicPlatform,$cordovaFile) {
this.getItems = function () {
$ionicPlatform.ready(function () {
// READ
$cordovaFile.readAsText(cordova.file.dataDirectory, "test.json")
.then(function (success) {
// success
items = success;
alert("SUCCESS A : >> " + items);
}, function (error) {
// error
alert("ERROR:" + error);
});
});
alert("SUCCESS B : >> " + items);
return items;
}
})