angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

FireStore timestampsInSnapshots

Open egaviriarestrepo opened this issue 8 years ago • 17 comments

Version info

**Angular:5.2.10 **Firebase:4.13.0 **AngularFire:5.0.0-rc.5-next

Debug output

** Errors in the JavaScript console ** ** Screenshots **

image

Steps to set up and reproduce

For now, i solve it like this; https://firebase.google.com/support/release-notes/js

export class CoreModule {

  constructor( ...,
               private afs: AngularFirestore) {

    const settings = {timestampsInSnapshots: true};
    afs.app.firestore().settings(settings);

   ...
  }
}

egaviriarestrepo avatar Apr 21 '18 20:04 egaviriarestrepo

I am not able to use your temporary solution when i have AngularFirestoreModule.enablePersistence()

Error i get:

ERROR Error: Firestore has already been started and its settings can no longer be changed. You can only call settings() before calling any other methods on a Firestore object.

tgangso avatar Apr 24 '18 19:04 tgangso

I have the same issue and the temporary fix didn't work for me

software770-2 avatar Apr 27 '18 20:04 software770-2

Sorry it's working, just put it in the config too and had to remove it from there: var firebaseConfig = { ... timestampsInSnapshots: true };

software770-2 avatar Apr 27 '18 20:04 software770-2

the same problem as @tgangso

abdellatifLabr avatar Apr 30 '18 13:04 abdellatifLabr

@tgangso I have the same issue here. Please have more details of how is it working. I've checked FirebaseAppConfig interface and it seems not having "timestampsInSnapshots"

export interface FirebaseAppConfig { apiKey?: string; authDomain?: string; databaseURL?: string; storageBucket?: string; messagingSenderId?: string; projectId?: string; }

I use the code below: AngularFireModule.initializeApp({...firebaseconfig, timestampsInSnapshots: true}), and it's not working. Please let me know how to add correct config to it. Thank you.

nathanfan46 avatar May 02 '18 01:05 nathanfan46

try something like this:

@NgModule( {
  imports: [
    ...,
    AngularFireModule.initializeApp( environment.firebase, 'XXX' ),
  ],
  declarations: [
    ...
  ],
  providers: [
    ...
  ]
} )
export class CoreModule {
  constructor( @Optional() @SkipSelf() parentModule: CoreModule,
               private afs: AngularFirestore ) {

    const settings = { timestampsInSnapshots: true };
    afs.app.firestore().settings( settings );

    ...
  }
}

if u need, use AppModule instead of CoreModule

egaviriarestrepo avatar May 02 '18 01:05 egaviriarestrepo

@egaviriarestrepo Thank you, but my issue is that our app need to enable offline support. So if I add "AngularFirestoreModule.enablePersistence()," I will get this error: console.error: Unhandled Promise rejection: Firestore has already been started and its settings can no longer be changed. You can only call settings() before calling any other methods on a Firestore object.

` @NgModule( { imports: [ ..., AngularFireModule.initializeApp( environment.firebase, 'XXX' ), AngularFirestoreModule.enablePersistence(), ], declarations: [ ... ], providers: [ ... ] } ) export class CoreModule { constructor( @Optional() @SkipSelf() parentModule: CoreModule, private afs: AngularFirestore ) {

const settings = { timestampsInSnapshots: true };
afs.app.firestore().settings( settings );

...

} } `

nathanfan46 avatar May 02 '18 02:05 nathanfan46

you can try, but i dont know if it work :

    afs.app.firestore().settings( settings );
    afs.app.firestore().enablePersistence();

and comment:

AngularFirestoreModule.enablePersistence()

egaviriarestrepo avatar May 02 '18 02:05 egaviriarestrepo

@egaviriarestrepo Thank you, it works. Import AngularFirestoreModule instead of AngularFirestoreModule.enablePersistence() then it's working.

nathanfan46 avatar May 02 '18 03:05 nathanfan46

@egaviriarestrepo Thank you made it work also like @nathanfan46 sais you have to remove enablePersistence from module load.

tgangso avatar May 02 '18 08:05 tgangso

This solution isn't working for me. I've modified my app.module.ts to look like this:

import { AngularFirestoreModule, AngularFirestore } from 'angularfire2/firestore';
...
  imports: [
    ...,
    AngularFireModule.initializeApp(environment.firebase, 'test-app'),
    AngularFirestoreModule
  ]
...
export class AppModule {
  constructor( @Optional() @SkipSelf() parentModule: AppModule,
                 private afs: AngularFirestore ) {

      const settings = { timestampsInSnapshots: true };
      afs.app.firestore().settings( settings );
    }
}

But I get the error error TS2339: Property 'app' does not exist on type 'AngularFirestore'.

ziftytodd avatar May 04 '18 21:05 ziftytodd

@ziftytodd Try afs.firestore.settings({timestampsInSnapshots: true});, that's what worked for me when I got that error.

pshields avatar May 04 '18 21:05 pshields

Just

import { AngularFirestoreModule, AngularFirestore } from 'angularfire2/firestore';

in your app.module then also in your app.module

export class AppModule {
   constructor(private afs: AngularFirestore) {
    afs.firestore.settings({
      timestampsInSnapshots: true,
    });
    afs.firestore.enablePersistence();
  }
 }

And we are fine since the dependency injector will always inject the configured instance thanks for all the suggestions. This one is working for me (Angular 6)

SaHeinem avatar May 11 '18 21:05 SaHeinem

Fixed in angularfire2@next

jamesdaniels avatar May 12 '18 22:05 jamesdaniels

Thank you so much @SaHeinem , worked well for me!!!

suvedhaGanapathy avatar May 18 '18 07:05 suvedhaGanapathy

and if I have active AngularFireAuthModule imports: [ ... AngularFireModule.initializeApp(firebaseConfig), // AngularFirestoreModule.enablePersistence(), AngularFireAuthModule, ... ],

josejaner avatar May 23 '18 01:05 josejaner

export class AppModule { constructor(private afs: AngularFirestore) { afs.firestore.settings({ timestampsInSnapshots: true, }); afs.firestore.enablePersistence(); } }

Doesn't work for me with [email protected]. I get: "ERROR Error: Uncaught (in promise): FirebaseError: [code=failed-precondition]: Firestore has already been started and persistence can no longer be enabled. You can only call enablePersistence() before calling any other methods on a Firestore object"

The same rearranging to enable persistence before applying settings: "Firestore already started, and settings cannot be changed anymore..."

I'm in a loop and cannot update to >rc.7 due to other dependencies in project not yet updated to use firebase >5.0.0

Any help?

pdela avatar May 23 '18 18:05 pdela