【发布时间】:2018-08-27 14:48:32
【问题描述】:
我目前正在开发一个有角度的网络应用程序,其中一个功能是照片上传。
我想对图像大小进行验证,以便在图像太小时抛出错误。
这是我的代码:
public onImageDrop(evt: any) {
evt.stopPropagation();
evt.preventDefault();
this.croppieImage = null;
this.onCropeMode = true;
const image: HTMLImageElement = new Image();
const file: File = evt.dataTransfer.files[0];
const myReader: FileReader = new FileReader();
myReader.onloadend = ((loadEvent: any) => {
image.src = loadEvent.target.result;
this.croppieImage = myReader.result;
});
myReader.readAsDataURL(file);
**console.log(image.height);
console.log(image.width);**
this.photoInDragMode = false;
this.uplodedPhotoFileName = file.name;
this.uplodedPhotoFileMimeType = file.type;
this.showPhotoSaveButton = true;
this.onCropeMode = true;
}
我的问题是
console.log(image.height);
console.log(image.width);
总是显示我
> 0
> 0
如果有人能提供帮助,我真的很感激。
提前谢谢各位。
【问题讨论】:
标签: javascript angular image typescript validation