Ricardo Cunha
Ricardo Cunha

Reputation: 2075

Angularfire2 how to set id on push

I have a little probelm using angularfire2 on ionic2, so I have and old firebase backend that is used by an android native app and now I'm rewriting this app using ionic2. So I have a database that saves facebook id like key and value, but I don't know how to do this using angularfire2, when I set the value in push firebase generates an automtic key and put my value. Any help?

My code:

let itemObservable = this.af.database.list('/confirmed/movie/mymovie');
itemObservable.push(this.firebaseAuth.facebook.uid);

My database:

enter image description here

Upvotes: 1

Views: 846

Answers (1)

Ricardo Cunha
Ricardo Cunha

Reputation: 2075

the secret is use update method, so I need to select an object and use an es6 trick:

    let myobject = this.af.database.object('/confirmed/movie/mymovie');

    let key = this.firebaseAuth.facebook.uid;
    myobject.update({[key]: this.firebaseAuth.facebook.uid});

Upvotes: 1

Related Questions