【发布时间】:2018-10-10 01:31:27
【问题描述】:
我正在尝试将 Firestore 文档的布尔字段从true 更新为false 或从false 更新为true,视情况而定。
当我激活和停用按钮时,它似乎工作正常,但在某些情况下它停止工作,我必须再次按下按钮。
这里是我的堆栈闪电战:https://stackblitz.com/edit/angular-ea3wme
myComponent.html
<mat-slide-toggle #toggle [checked]="domiciliario.estado" (change)="actualizarEstado(domiciliario.id)"></mat-slide-toggle>
myComponent.ts
actualizarEstado(key){
this.fs.updateEstado(key);
}
myService.ts
estadoChange: boolean = !false || !true;
updateEstado(key){
this.afs.doc('domiciliarios/' + key).update({
estado : this.estadoChange = !this.estadoChange
})
}
【问题讨论】:
-
在您的服务中,您在所有
domiciliarios中使用相同的estadoChange值。您需要切换正在由切换器编辑的特定domiciliario的estado属性。
标签: angular typescript angular-material google-cloud-firestore