You should add providers: [AngularFirestore]
in app.module.ts
.
@NgModule({
imports: [
BrowserModule,
AngularFireModule.initializeApp(environment.firebase)
],
declarations: [ AppComponent ],
providers: [AngularFirestore],
bootstrap: [ AppComponent ]
})
export class AppModule {}
I had same issue and below is resolved.
Old Service Code:
@Injectable()
Updated working Service Code:
@Injectable({
providedIn: 'root'
})
Open: ./src/app/app.module.ts
And import Firebase Modules at the top:
import { environment } from '../environments/environment';
import { AngularFireModule } from 'angularfire2';
import { AngularFirestoreModule } from 'angularfire2/firestore';
And VERY IMPORTANT:
Remember to update 'imports' in NgModule:
@NgModule({
declarations: [
AppComponent,
OtherComponent // Add other components here
...
],
imports: [
BrowserModule,
AngularFireModule.initializeApp(environment.firebase, 'your-APP-name-here'),
AngularFirestoreModule
],
...
})
Give it a try, it shall now work.
For detailed information follow the angularfire2 documentation:
https://github.com/angular/angularfire2/blob/master/docs/install-and-setup.md
Good luck!
Weird thing for me was that I had the provider:[]
, but the HTML tag that uses the provider was what was causing the error. I'm referring to the red box below:
It turns out I had two classes in different components with the same "employee-list.component.ts" filename and so the project compiled fine, but the references were all messed up.
Adding AngularFirestoreModule.enablePersistence()
in import section resolved my issue:
imports: [
BrowserModule, AngularFireModule,
AngularFireModule.initializeApp(config),
AngularFirestoreModule.enablePersistence()
]
I solved this problem by just removing firestore from:
import { AngularFirestore } from '@angular/fire/firestore/firestore';
in my component.ts file. as use only:
import { AngularFirestore } from '@angular/fire/firestore';
this can be also your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With