Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda