Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularFire2 - Setting custom key when pushing

I am learning angularfire2 in Ionic2

 const newUser = this._db.list('/users');
  setTimeout(() => {
    newUser.push(this.userInfo)
      .then((data) => console.log(data))
  },3000)

I want to know if there is any way I can set my custom key when pushing new data. I tried various suggestion given on internet to update the key after insert, but no success.

like image 326
raju Avatar asked Aug 27 '17 13:08

raju


1 Answers

Rather than .push, I tried .set

const userList = this._angualrFireDB.list('/users');
userList.set(this.userAuthData.uid,
  {
    name: 'Ashwin',
    age: 38,
    dob: '10/11/1978',
    uid: this.userAuthData.uid
  });

This works, and I am getting my uid as my new key.

like image 138
raju Avatar answered Oct 22 '22 10:10

raju