在 Visual Studio 类型 FileReader 中使用 angular2-img-cropper 时的 Angular2 错误不可分配给类型 FileReader [英] Angular2 Error when using angular2-img-cropper in Visual Studio Type FileReader is not assignable to type FileReader

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

问题描述

我只是尝试探索插件 angular2-img-cropper (https://github.com/cstefanache/angular2-img-cropper) 并添加了一些来自 plunker 的示例代码 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

实际的错误在上面plunker的下面一段代码中:

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 类型 FileReader 中使用 angular2-img-cropper 时的 Angular2 错误不可分配给类型 FileReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆