this is my Html5 code :
<div>
<input type="file" multiple (change)="comPress($event.target.files)">
</div>
i need on change do this function comPress() with all files. this is in Angular component.ts :
comPress(images){
function fetchResult(img) {
return new Promise( function(resolve, reject) {
let data = [];
for(let i of img){
var reader = new FileReader();
reader.onload = function (e) {
data = [...data, e.target['result']];
}
reader.readAsDataURL(i);
}
resolve(data);
reject('reject');
})
};
fetchResult(images).then(data=>{
console.log(data) // is always []
}).catch(err=>console.log(err))
}
i need push this variable let data = [];
with all result data from function onload()
but the result is always []
empty array!
I expect this result :
["data:sadvdsbdsbdsvdsvdsbdb", "data:vaswbvewbewbregergreg"]
What is wrong with this code?