ropper时出现Angular2错误不能将FileReader

ropper时出现Angular2错误不能将FileReader

本文介绍了在Visual Studio中使用angular2-img-cropper时出现Angular2错误不能将FileReader类型分配给FileReader类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是尝试探索插件angular2-img-cropper( https://github.com/cstefanache/angular2-img-cropper ),并添加了来自监听器 https://的示例代码embed.plnkr.co/V91mKCNkBQZB5QO2MUP4/到我的应用中.

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.

但是当我尝试在Visual Studio 2015中编译我的应用程序时,出现以下错误:

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);
    }

任何人都可以指导吗?

推荐答案

解决方案是替换为事件侦听器:

The solution is to replace with event listener:

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

这篇关于在Visual Studio中使用angular2-img-cropper时出现Angular2错误不能将FileReader类型分配给FileReader类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:48