标签: photoeditorsdk

在异步中使用promises时捕获HTML5 FileReader的结果

我有一个Angular 4应用程序,我正在读取一个图像并尝试将base64字符串传递给另一个变量 - 但是我遇到了一个问题,因为它的异步性质 - image.src是空的,因此值已正确传递给图像宾语?

ngAfterViewInit(): void {
    let image = new Image();
    var promise = this.getBase64(fileObject, this.processImage());
    promise.then(function(base64) {
        console.log(base64);    // outputs string e.g 'data:image/jpeg;base64,........'
    });

    image.src = base64; // how to get base64 string into image.src var here??

    let editor = new PhotoEditorSDK.UI.ReactUI({
        container: this.editor.nativeElement
        editor: {
           image: image
        }
    });
}

/**
 * get base64 string from supplied file object
 */
public getBase64(file, onLoadCallback) {
    return new Promise(function(resolve, reject) {
        var reader = new FileReader(); …
Run Code Online (Sandbox Code Playgroud)

html5 typescript es6-promise angular photoeditorsdk

6
推荐指数
2
解决办法
677
查看次数

标签 统计

angular ×1

es6-promise ×1

html5 ×1

photoeditorsdk ×1

typescript ×1