Angularfire: `$ref` no longer available, can't do `onDisconnect` calls anymore.

Created on 20 Oct 2017  路  7Comments  路  Source: angular/angularfire

Version info

Angular: 4.4.6

Firebase: 4.6.0

AngularFire: 5.0.0-rc.3

Other (e.g. Ionic/Cordova, Node, browser, operating system):

How to reproduce these conditions

Prior to upgrading to v5, the following code worked.

let donuts = this.db.object(`DONUTS`);
donuts.$ref.onDisconnect().set(false);

Now it no longer works as I can't access the $ref property from the result of the call to this.db.object(). Any ideas on how I might regain onDisconnect functionality? I didn't see this change in the migration docs, so this caught me off guard.

Most helpful comment

Hey @aaronfrost! The query/ref is available on the AngularFireObject service, it's just called query now.

ts let donuts = this.db.object(`DONUTS`); // make sure to call .ref because you could be dealing with a query. Both Query and Reference have a .ref property to deal with this case. donuts.query.ref.onDisconnect().set(false);

Thanks for flagging this, we'll update our migration guide to indicate this.

All 7 comments

you should search for transaction issue before open this, there is an answer here and I tried, it work:
hope that help :)

let donuts = this.db.object(`DONUTS`)
donuts.snapshotChanges()
.subscribe( action => action.payload.ref.onDisconnect().set(false));

rtdb Lists document sample still used $ref

The above solution may work but it is unsatisfactory. It should not be necessary to open a subscription in order to access the ref or the onDisconnect() method. It would be preferable if both of these could be added to the AngularFireObject and AngularFireList classes.

I agree with @jaufgang. The ref should be exposed differently, and that the proposed "solution" is more of a workaround, than a solution. Having to snapshotChanges and then subscribe, so that I can simply get a pointer to the ref is a lot of hoops that were't necessary before. Since the API is being rev'd, this should be considered.

Hey @aaronfrost! The query/ref is available on the AngularFireObject service, it's just called query now.

ts let donuts = this.db.object(`DONUTS`); // make sure to call .ref because you could be dealing with a query. Both Query and Reference have a .ref property to deal with this case. donuts.query.ref.onDisconnect().set(false);

Thanks for flagging this, we'll update our migration guide to indicate this.

wow that good 馃憤

@aaronfrost what up man!

@davideast I don't see .query mentioned anywhere in the docs either.

Closing, outdated. Solution in 5.0, keep a reference to the ref around (and build it with the firebase js sdk methods + pass into AF2) if you need to access methods on it.

Was this page helpful?
0 / 5 - 0 ratings