Good afternoon, I have the following problem, I have a cycle for which I get, do a tour and print some emails, so far so good, the detail is that I want to show all the emails that I get in an input, but it only shows me 1 which it is the last.
My code is the following:
openDialogEnviarCorreosMasivos() {
this.dialogEnviarCorreosMasivos = true;
for (let correos of this.selectedInstitucions) {
//console.log(correos)
this.m_ecm_correos_seleccionados = correos.correo_institucion;
console.log(this.m_ecm_correos_seleccionados)
}
console.log(this.m_ecm_correos_seleccionados)
}
and I want to show it in an input with the ngmodel m_ecm_correos_seleccionados but I don't get that part.
<div class="field col-12 md:col-12">
<label class="font-bold">Correos selecionados</label>
<p-chips placeholder="Correos seleccionados" separator="," [(ngModel)]="m_ecm_correos_seleccionados" placeholder=""></p-chips>
</div>
In the loop what you are doing is overwriting the value of the property
m_ecm_correos_seleccionados
in each iteration. That's why in the end the value you have left is the email of the last element.What you have to do is create a new array and save all the emails in it.
Using the
for...of
loop it would be something like this:You can also do it in a more compact way using the method directly
map
on the array of selects, indicating in its mapping function what you want to keep from each element.a greeting