NullInjectorError: No provider for AngularFirestore

前端 未结 11 858
北恋
北恋 2020-12-02 10:34

I\'m learning Angular looking for help in fixing the error: I\'m following this link : https://github.com/angular/angularfire2/blob/master/docs/install-and-setup.md to creat

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 11:30

    I had the same issue while adding firebase to my Ionic App. To fix the issue I followed these steps:

    npm install @angular/fire firebase --save
    

    In my app/app.module.ts:

    ...
    import { AngularFireModule } from '@angular/fire';
    import { environment } from '../environments/environment';
    import { AngularFirestoreModule, SETTINGS } from '@angular/fire/firestore';
    
    @NgModule({
      declarations: [AppComponent],
      entryComponents: [],
      imports: [
        BrowserModule, 
        AppRoutingModule,
        AngularFireModule.initializeApp(environment.firebase),
        AngularFirestoreModule
      ],
      providers: [
        { provide: SETTINGS, useValue: {} }
      ],
      bootstrap: [AppComponent]
    })
    

    Previously we used FirestoreSettingsToken instead of SETTINGS. But that bug got resolved, now we use SETTINGS. (link)

    In my app/services/myService.ts I imported as:

    import { AngularFirestore } from "@angular/fire/firestore";
    

    For some reason vscode was importing it as "@angular/fire/firestore/firestore";I After changing it for "@angular/fire/firestore"; the issue got resolved!

提交回复
热议问题