Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
Checkbox field immediately gets unchecked after checking in Angular/Ionic app

I have a series of data that I am looping through in my app. Each item contains the field checked that represents whether or not the checkbox for that item should be checked. By default, that is set to checked: false in my list.html file.

<ion-item lines="full" *ngFor="let item of items">
    <ion-label [class.strike]="item.checked" class="ion-padding ion-text-wrap">
        {{ item.title }}
    </ion-label>
    <ion-checkbox slot="start" [(ngModel)]="item.checked" mode="ios" (ionChange)="itemChecked(item)"></ion-checkbox>
</ion-item>

On change of the checkbox being selected using the ionChange, I call my itemChecked method pass my item to it.

async itemChecked(item: Item) {
    console.log(item); //I can see checked has been updated.
    await this.firestore.updateItemKey(item, 'checked');
}

Then, in my firestore service file, I update the document like so:

updateItemKey(item: Item, key: string) {
    const itemDocRef = doc(this.firestore, `items/${item.id}`);
    return updateDoc(itemDocRef, { key: item[key] });
}

However, back in my list.html file, the item is not being checked and nothing is being correctly updated in my firebase database? The item quickly shows as checked then immediately goes back to unchecked.

Any thoughts on what I may have overlooked or done incorrectly that is causing this issue?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of [(ngModel)]="item.checked" I think you should just go with [checked]="item.checked", and in itemChecked() do item.checked = !item.checked because you'd want to update the [checked] binding with new value. Of course, you should handle checked==false result of ionChange too.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda