Ionic app written in typescript:
let files: any[] = [];
files =this.getFiles("wildlife");
console.log("files:", files);
this.render(files);
which is strange, cause although there are 50 items there but it shows Array(0). Problem is when i pass this array in function:
render( files)
{
files.forEach(item => {
console.log(item) <- does not exist
});
}
Array is empty. Why is that ? Is there other way to pass the array and loop through its objects ?
EDIT:
getFiles(folder) {
let files: any[] = [];
this.file.listDir(this.file.applicationDirectory, 'www/assets/' + folder)
.then((items) => {
// console.log(items);
items.forEach(item => {
files.push({
filename: item.name,
name: this.getName( item.name)
});
});
})
.catch(err =>
console.log("error: ", err));
return files;
}