更新Firebase增量数据

时间:2018-10-02 03:18:19

标签: typescript firebase ionic-framework firebase-realtime-database

我正在尝试实现Facebook的“赞”按钮,当用户单击该按钮时,数据将增加,firebase中的数据将被更新。在这种情况下,我想更新加入事件的人数,例如数据库中的加入人数为0,当用户单击按钮时,加入人数为1。问题是,数据甚至都没有改变。

Home.html

<ion-card *ngFor="let event of (eventList$ | async)?.slice().reverse()" navPush="EventPage" [navParams]="{event: event}">
  <ion-col>
    <button ion-button round (click)="joinAdd()">Join Event</button>
  </ion-col>
</ion-card>

Home.ts

import { EventDetail } from '../../models/event-detail/event-detail.interface';
import { Observable } from 'rxjs';

eventListRef$: AngularFireList<EventDetail>;
eventList$: Observable<EventDetail[]>;
updateEvent = {} as EventDetail;

constructor(...) {
  this.database.list<EventDetail>('event-list').valueChanges().subscribe((eventData) => { 
  console.log("Event details data", eventData);
  }, (err)=>{
    console.log("Error while retrieving event details : ", err);
  }); 

  this.eventListRef$ = this.database.list<EventDetail>('event-list');
  this.eventList$ = this.eventListRef$.valueChanges();

}

joinAdd(updateEvent: EventDetail,) {
  this.updateEvent.$key = this.updateEvent.$key,
  this.updateEvent.eventName = this.updateEvent.eventName,
  this.updateEvent.eventDesc = this.updateEvent.eventDesc,
  this.updateEvent.address = this.updateEvent.address,
  this.updateEvent.startDate = this.updateEvent.startDate,
  this.updateEvent.endDate = this.updateEvent.endDate,
  this.updateEvent.startTime = this.updateEvent.startTime,
  this.updateEvent.endTime = this.updateEvent.endTime,
  this.updateEvent.noV = this.updateEvent.noV,
  this.updateEvent.image = this.updateEvent.image,
  this.updateEvent.join = this.updateEvent.join++;

this.eventListRef$.update(this.updateEvent.$key, updateEvent);


    }

}

堆栈跟踪

TypeError: Cannot read property 'set' of undefined
  at isFirebaseRef (http://localhost:8101/build/vendor.js:52113:25)
  at checkOperationCases (http://localhost:8101/build/vendor.js:52123:14)
  at Object.dataOperation [as update] (http://localhost:8101/build/vendor.js:171043:91)
  at HomePage.webpackJsonp.537.HomePage.joinAdd (http://localhost:8101/build/0.js:6419:28)
  at Object.eval [as handleEvent] (ng:///HomePageModule/HomePage.ngfactory.js:87:31)
  at handleEvent (http://localhost:8101/build/vendor.js:13963:155)
  at callWithDebugContext (http://localhost:8101/build/vendor.js:15472:42)
  at Object.debugHandleEvent [as handleEvent] (http://localhost:8101/build/vendor.js:15059:12)
  at dispatchEvent (http://localhost:8101/build/vendor.js:10378:25)
  at http://localhost:8101/build/vendor.js:11003:38

我遵循了3种不同的YouTube教程,在这一点上,我确实感到困惑。

0 个答案:

没有答案