How can I preview multiple images that I have selected before uploading them in Angular?
I have managed to do it but only with one image, even though I select several, only one recognizes me. I think the use of *ngFor
is a good alternative but I'm not sure how to raise it. Any ideas?
myComponent.html
<img *ngIf="url" [src]="url" class="rounded mb-3" width="180">
<input type="file" multiple (change)="detectFiles($event)">
myComponent.ts
detectFiles(event) {
this.selectedFiles = event.target.files;
if (event.target.files && event.target.files[0]) {
var reader = new FileReader();
reader.onload = (event: any) => {
this.url = event.target.result;
}
reader.readAsDataURL(event.target.files[0]);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…