如何在Angular中按顺序处理2个点击事件

问题描述 投票:1回答:2
<button class="post-save" (click)="fileUpload.upload()" (click)="editor.save()"> save </button>

按下保存按钮时

单击“事件1:文件上载”

单击事件2:发布保存

当我点击“文件上传”时,它会收到网址作为返回值。

并且'editor.save()'是'保存返回网址'。

所以我想在'Event 1'结束后运行'Event 2'。

我该如何解决?

html angular events click inorder
2个回答
0
投票

你应该只调用一个函数。我怀疑fileUpload.upload()是异步的,所以一种方法是:

newFunction(){
    this.fileUpload.upload().subscribe(data => {
      // do what you do when the file is uploaded
      this.editor.save();
    }
}

0
投票

您可以通过分隔分号在任何情况下调用两种或更多种方法;

像这样,

<button class="post-save" (click)="editor.save(); fileUpload.upload()"> save </button>
© www.soinside.com 2019 - 2024. All rights reserved.