0
votes

Have below piece of code:

getRegistrations(){
  this.registrationList = this.firebase.list('registrations');
  return this.registrationList.snapshotChanges();
}

insertRegistration(registration){
  this.registrationList.push({
    firstname: registration.firstname,
    lastname: registration.lastname,
    phone: registration.phone,
    email: registration.email,
    password: registration.password
  });
}

Getting below error:

ERROR TypeError: Cannot read property 'push' of undefined

2
I m not sure about its type: check typeof(this.registrationList) inside insertRegistration method:Prashant Pimpale

2 Answers

0
votes

Try This,

insertRegistration(registration){
  this.registrationList = [];
  this.registrationList.push({
  firstname: registration.firstname,
  lastname: registration.lastname,
  phone: registration.phone,
  email: registration.email,
  password: registration.password
  });
  }
0
votes

Cannot read property 'push' of undefined

This is because of this.registrationList is getting undefined when you are calling insertRegistration() or you are not Initializing it.

You can check the value if it and In case it's undefined then assign empty array to it.

  getRegistrations() {
     this.registrationList = this.firebase.list('registrations');
     return this.registrationList.snapshotChanges();
  }

  insertRegistration(registration) {
     this.registrationList = this.registrationList : this.registrationList ? [];
     this.registrationList.push({
       firstname: registration.firstname,
       lastname: registration.lastname,
       phone: registration.phone,
       email: registration.email,
       password: registration.password
    });
  }

I hope this will work.. :)