我正在使用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); }}
}
bcc没有正确填充。我该如何解决?
对属性支持字符串。您必须将数组转换为字符串。
您可以以这种方式转换。
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"