How to validate image size? (ex: less than 2MB) I'm using ng2-file-input for image uploading in my angular4 project.
`
public onAction(event: any) {
this.resImagesSize = event.currentFiles;
for (let i = 0; i < this.resImagesSize[i].size; i++) {
if (this.resImagesSize[i].size > 2000000) {
this.toasterService.pop('error', 'Error', 'Please upload less than 2MB image');
this.resImagesSize.splice(i, 1);
} else {
this.resImages = this.resImagesSize;
}
}
}
`
Edit: here is my toasterService code `
toasterconfig: ToasterConfig =
new ToasterConfig({
tapToDismiss: true,
timeout: 5000,
preventDuplicates: false,
positionClass: 'toast-top-center'
});
`
problem is when i upload more than 2 images(bigger than 2MB) it display 2 messages. How to display only one validation message ?