Angular 2/4 中的鸟舍 (Adobe Creative SDK) 在启动图像编辑器并按下"保存"按钮时无法访问类变量



我在 plunker 上创建了示例代码 https://plnkr.co/edit/kBZGz6pRlErV6hV08ctX?p=preview

一切正常,但是当编辑器启动时,我无法访问类变量或类中的任何其他成员

imageCropMsg: string = "";

当编辑器启动时,此变量和所有其他变量在内部变得未定义

onSave: function(imageID: string, newURL: string) {
    debugger;
    var img:any = document.getElementById(imageID);
    img.src = newURL;
    this.imageCropMsg = "Image Cropped Successfully";
    this.featherEditor.close();
}

不幸的是,我找不到任何原因并解决了这个问题。

另外,如果有人可以改进代码,我将不胜感激。

这个问题与javascript中的"this"上下文有关。尝试将函数更改为箭头函数。

onSave: (imageID: string, newURL: string) => {
            var img:any = document.getElementById(imageID);
            img.src = newURL;
            this.imageCropMsg = "Image Cropped Successfully";
            this.featherEditor.close();
        }

有了这个,您可以访问这个和所有变量

最新更新