【问题标题】:Ionic Native Email Composer - Passing ngModel as arrayIonic Native Email Composer - 将 ngModel 作为数组传递
【发布时间】:2018-05-09 00:36:33
【问题描述】:

我正在使用 Ionic 的电子邮件编辑器插件,并希望从页面获取输入并将它们作为数组传递到电子邮件中,以便可以一次向多个用户发送电子邮件。目前,仅传递输入的第一封电子邮件,而不是全部。

HTML 是:

<ion-content>

   <ion-item id="row" *ngFor="let emailinput of emailinputs ; let i = index">
      <ion-label fixed id="label">
        Email
      </ion-label>
         <ion-input type="email" id="email" placeholder="jdoe@gmail.com" (keyup.enter)="Send($event.target.value)" [(ngModel)]="emailinputs[i].email"></ion-input>
   </ion-item>

   <div padding>
      <button (click) = "addnewemail()" id="register" ion-button full color="nudgetprim" block>Add</button>
      <button (click) = "sendinvite(emailinputs.email)" id="register" ion-button full color="nudgetprim" block>Invite</button>
   </div>

</ion-content>

打字稿是:

sendinvite() {
      var bcc = [];
      for(var e in this.emailinputs){
      if (this.emailinputs[e].email==null || this.emailinputs[e].email=="" || !this.emailinputs[e].email.includes("@") || !this.emailinputs[e].email.includes("."))
        {
          let alert = this.alerCtrl.create({
                title: 'Error!',
                message: 'There was an error with an email address you entered.',
                buttons: ['Ok']
              });
              alert.present()
            }
      else {
      bcc.push(this.emailinputs[e].email);
      this.emailComposer.isAvailable().then((available: boolean) =>{
       if(available) {
         //Now we know we can send
       }
      });

      let email = {
        // to: this.emailVal,
        // cc: 'erika@mustermann.de',
        bcc: bcc,
        attachments: [
          'file://img/logo.png',
          'res://icon.png',
          'base64:icon.png//iVBORw0KGgoAAAANSUhEUg...',
          'file://README.pdf'
        ],
        subject: 'Nudget Invite',
        body: '<a href="">Join my grocery list!</a>',
        isHtml: true
      };

      // Send a text message using default options
      this.emailComposer.open(email);        }}
    }

密件抄送未正确填充。我该如何解决这个问题?

【问题讨论】:

    标签: angular typescript ionic-framework ionic2 ionic3


    【解决方案1】:

    To 属性支持字符串。您必须将数组转换为字符串。

    你可以这样转换。

    const emailVal = ['aa@aa.com', 'bb@aa.com'];
    let emailTo = '';
    emailVal.map((email, index) => {
        console.log(email, index)
        if (index === emailVal.length - 1) {
          emailTo = emailTo + email;
        } else {
            emailTo = emailTo + email + ', ';
        }
    });
    
    console.log(emailTo);
    
    // result
    // "aa@aa.com, bb@aa.com"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-12
      • 2022-01-24
      • 1970-01-01
      • 2021-05-26
      • 1970-01-01
      • 2011-08-12
      相关资源
      最近更新 更多