0

我从 froala 编辑器(Angular io)将图像上传到 S3,现在我想将该链接存储在一个变量中。我该怎么做?下面是我如何尝试

export class WriterComponent implements OnInit {
   imageLink:string;
   constructor() { }
   ngOnInit() {
     this._usersService.getS3Hash().subscribe(resp=>{
        this.options['imageUploadToS3'] = resp;
     });
   }

   public options:Object={
     heightMin:300,
     events:{
        'froalaEditor.image.uploadedToS3': function (e,editor,link,key,response) {
         // save the link
         this.imageLink=link;
   }
}

HTML文件中的froala编辑器

    <textarea [froalaEditor]="options" ngModel name="inputcontent"></textarea>

但是在上传图像后,当我显示imageLink时它显示为空。

这似乎是上下文问题,因为imageLink使用的是 froala 编辑器上下文而不是组件。

4

1 回答 1

1

不确定您对此编辑器的配置,但这些更改可能对您有用

export class WriterComponent implements OnInit {
   imageLink:string;
   constructor() { }
   ngOnInit() {
     this._usersService.getS3Hash().subscribe(resp=>{
        // this.options['imageUploadToS3'] = resp; // you are assigning your response to `imageUploadToS3` which doesn't exist on options object. so changes it as
        this.options.events['imageUploadToS3'] = resp;
     });
   }

   public options:Object={
     heightMin:300,
     events:{
        'imageUploadToS3': (e,editor,link,key,response) => {    //Second change your function with arrow function here
         // save the link
         this.imageLink=link;
   }
}

如果仍然有错误,请告诉我,如果您使用诸如 plunker 或 stackblitz 之类的工作链接更新您的问题,则更好

于 2018-05-12T09:07:50.833 回答