我正在尝试上传文件并裁剪屏幕上显示的图像,但是我一直都在看到此错误-知道吗?
ERROR TypeError: Cannot read property 'setImage' of undefined
at FileReader.myReader.onloadend
我在文件上传方法中设置了setImage(Image),如下所示,但仍然给我带来了问题-
fileChangeListener($event) {
myReader.onloadend = function (loadEvent:any) {
image.src = loadEvent.target.result;
that.cropper1.setImage(image);
};
}
答案 0 :(得分:0)
fileChangeListener($event) {
myReader.onloadend = (loadEvent:any) => { // replace function with => arrow
image.src = loadEvent.target.result;
this.cropper1.setImage(image); // that should be this
};
}