Hi, i am trying to use conditional json file if user has internet and was able to download the json, checkfile it then return the value to be run on processData() and back to getSpeakers();
however if user fails to download new json it will use the stock json from app, but if a new stored json exist it will use the previously stored one…
load(): any {
var language = "-" + window.localStorage.getItem("lang");
var locdata = "lang/";
const fileTransfertdata: FileTransferObject = this.transfer.create();
const urldata= 'http://website.com/appJson/data'+language+'.json';
fileTransfertdata.download(urldata, this.file.dataDirectory+locdata +'online-data'+language+'.json').then((entry) => {
console.log("-----------download completeeeeee");
var newdata = entry.toURL();
console.log(newdata);
this.file.checkFile(this.file.dataDirectory+locdata, 'online-data'+language+'.json').then((file) => {
console.log("check sucess");
//use fresh new data
return this.http.get(this.file.dataDirectory+locdata +'online-data'+language+'.json').map(this.processData, this);
}, (err) => {
console.log(" ----------- check error");
console.log(err);
//use stock data
return this.http.get('assets/data/data'+language+'.json').map(this.processData, this);
});
}, (error) => {
// handle error
console.log(" ----------- download error");
console.log(error);
this.file.checkFile(this.file.dataDirectory+locdata, 'online-data'+language+'.json').then((file) => {
console.log("----------- download error + check sucess");
//use previously stored data
return this.http.get(this.file.dataDirectory+locdata +'online-data'+language+'.json').map(this.processData, this);
}, (err) => {
console.log(" ----------- download + check error");
console.log(err);
//use stock data
return this.http.get('assets/data/data'+language+'.json').map(this.processData, this);
});
});
}
im currently getting : TypeError: undefined is not an object (evaluating ‘this.load().map’)
on
getSpeakers() {
return this.load().map((data: any) => {
return data.speakers.sort((a: any, b: any) => {
let aName = a.order.split(' ').pop();
let bName = b.order.split(' ').pop();
return aName.localeCompare(bName);
});
});
}
if i don’t put the return inside the download or checkfile the app fully works. But when the return is placed inside the THEN i get the error above.
Thanks guys, hopefully someone can assist me…