angularfirebaseangular-injector

AngularFireModule.initialize causing NG0203 error


I'm learning angular and I'm going through a tutorial on how to setup Angular with firebase. But I get the following runtime error: "NG0203: inject() must be called from an injection context such as a constructor..."

enter image description here

Here is my code: enter image description here

I've tried using the following solutions: https://github.com/angular/angularfire/issues/1635 https://codinglatte.com/posts/how-to/how-to-setup-firebase-for-angular/

If I remove compat from the firebase path I get compile time errors. If I remove the Initialize method, nothing changes at runtime.


Solution

  • This might be a problem related to the version of Angular and AngularFire that you are using. Try to replace:

    AngularFireModule.initializeApp(environment.firebase)
    

    with:

    provideFirebaseApp(() => initializeApp(environment.firebase))
    

    In my case this solved the issue.