AngularJS promise not resolving file with FileReader

This question already has an answer here:

  • How do I convert an existing callback API to promises? 17 answers

  • 您没有onload事件,因此它实际上不会返回读取的文件数据。

    this.fileRead  = function(file) {
        var deferred = $q.defer();
    
        var reader = new FileReader();
    
        reader.onload = function() {
            deferred.resolve(reader.result);
        };
    
        reader.readAsDataURL(file);
    
        return deferred.promise;
    };
    
    链接地址: http://www.djcxy.com/p/55518.html

    上一篇: Angular2:回归诺言

    下一篇: AngularJS承诺不使用FileReader解析文件