-
Notifications
You must be signed in to change notification settings - Fork 2.2k
-
I tried this
import { Injectable } from '@angular/core';
import { doc, enableIndexedDbPersistence, getFirestore, provideFirestore } from '@angular/fire/firestore';
import { setDoc } from '@firebase/firestore';
@Injectable({
providedIn: 'root'
})
export class UserDataService {
firestore:any;
constructor() {
this.firestore = provideFirestore(() => {
this.firestore = getFirestore();
enableIndexedDbPersistence(this.firestore);
return this.firestore;
});
}
addNewUser(): void {
console.log('addNewUser',this.firestore);
const userDoc = doc(this.firestore, 'users/user1');
console.log(userDoc);
setDoc(userDoc, {'Alpha':'beta'}).then(() => {
console.log('Document successfully written!');
}).catch(() => {
console.log('Error writing document');
});
}
}
but it doesn't work I know angular/fire 7 is new and docs are not ready but I really want to know how it works. I know I am doing something wrong here.
Please provide an easy solution to this.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
Answered by
hakimio
Oct 25, 2021
- You have to provide Firestore in app module and then inject it in your service.
-
provideFirestore()
returnsModuleWithProviders<FirestoreModule>
notFirestore
instance. You are misusing it.
Replies: 1 comment 2 replies
-
- You have to provide Firestore in app module and then inject it in your service.
provideFirestore()
returnsModuleWithProviders<FirestoreModule>
notFirestore
instance. You are misusing it.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
2 replies
-
Can you show an example of how to do it?
Beta Was this translation helpful? Give feedback.
All reactions
-
I linked to the example in my answer.
Beta Was this translation helpful? Give feedback.
All reactions
Answer selected by
Sapython
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment