FileReader在Ionic 2中没有触发onloadend

use*_*375 4 javascript plugins file cordova ionic-framework

我正在尝试使用cordova-file-plugin读取本地文件.目前,我能够读取本地目录的内容并选择单个文件.但是我有问题要获取文件的内容.

这是从列表中选择文件后单击按钮调用的函数:

import() {
    window.resolveLocalFileSystemURL(this.file.nativeURL, this.gotFile, this.fail);
}
Run Code Online (Sandbox Code Playgroud)

这里有两个函数gotFile失败:

fail(e) {
    console.log(e);
}

gotFile(fileEntry) {
    var file = fileEntry.nativeURL;

    fileEntry.file(function(file) {
        var reader = new FileReader();

        reader.onloadend = function(e) {
             console.log('onloadend()'); 
        };

        reader.readAsText(file);

        console.log(reader);
    }); 
}
Run Code Online (Sandbox Code Playgroud)

我可以在日志中看到读者结果中包含我文件的所有想要的内容,但是我无法得到它并使用它.该readyState的是2,但所有的内部reader.onloadend不叫.使用Ionic 1,此代码可以正常运行.

如果有人能帮助我,我会很高兴的.提前致谢!

Par*_*iya 9

离子2中的已知问题

在cordova.js修复之前加载zone.js.

特定于ionic2维持此序列顺序.

<script src="build/polyfills.js"></script> <script src="cordova.js"</script>

当polyfills.js执行zone.js.


小智 2

虽然我没有使用过onloadend,但我已经onload在 Ionic 2 中成功使用了事件处理程序,也许你可以尝试一下。

请记住,仅当操作成功时它才会返回。