角度2启动和停止机制

时间:2017-03-13 10:21:46

标签: angular for-loop

在我的邮件应用程序中,我使用电子邮件地址的预加载列表发送电子邮件,并使用循环内置功能自动发送电子邮件

startEmailing() {

      var headers = new Headers();

      headers.append("Content-Type", 'application/json');
      headers.append("Accept", 'application/json');

      for (var i = this.emails.length - 1; i >= 0; i--) {

        var message = {

        mail_driver: this.mail_driver,
        mail_host: this.mail_host,
        mail_port: this.mail_port,
        mail_encryption: this.mail_encryption,
        mail_username: this.mail_username,
        mail_password: this.mail_password,
        email_body: this.email_body,
        email_subject: this.email_subject,

        email: this.emails[i],
        attachments: this.uploadedFiles

      }

      this.http
      .post(this.api_server_postSingpleEmail, JSON.stringify(message), {headers: headers})
      .map(res => res.json())
      .subscribe(
        response => {

          if(response.success) {

            this.emails[response.data.email.id].status = true;

          }  else {

            this.msgs = [];
            this.msgs.push({severity: 'error', summary: 'Error', detail: 'Sending message for ' + this.emails[response.data.email.id].name + ' has failed.'});

            this._log += this.emails[response.data.email.id].name + "\n";
            console.log(this._log);

          }

        },
        err => {console.log(err)})
      }
    }

问题是,如何在按钮上实现启动停止机制?所以,我们说我发了50封电子邮件并点击停止,循环将停止并等待我再次点击开始按钮继续发送?

0 个答案:

没有答案