Angular2 Error when using angular2-img-cropper in Visual Studio Type FileReader is not assignable to type FileReader

孤街浪徒 提交于 2020-01-03 04:48:12

问题


I just tried to explore plugin angular2-img-cropper (https://github.com/cstefanache/angular2-img-cropper) and added some of the sample code from the plunker https://embed.plnkr.co/V91mKCNkBQZB5QO2MUP4/ to my app.

But when I try to compile my app in Visual Studio 2015, its giving below error:

Type FileReader is not assignable to type FileReader. Property onloadend is missing in type FileReader

The actual error is in the below piece of code from above plunker:

fileChangeListener($event) {
        var image:any = new Image();
        var file:File = $event.target.files[0];
        var myReader:FileReader = new FileReader();
        var that = this;
        myReader.onloadend = function (loadEvent:any) {
            image.src = loadEvent.target.result;
            that.cropper.setImage(image);

        };

        myReader.readAsDataURL(file);
    }

Can anyone please guide?


回答1:


The solution is to replace with event listener:

fileReader.addEventListener('loadend', function(loadEvent:any){
    image.src = loadEvent.target.result;
    that.setImage(image);
});


来源:https://stackoverflow.com/questions/38963494/angular2-error-when-using-angular2-img-cropper-in-visual-studio-type-filereader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!