Issue
Running into this error... this is the solution to a previous error i ran into.
https://stackoverflow.com/a/59614334/17666012
consent.component.ts
ngOnInit(){
this.db.getAgents().subscribe((data) => {
this.agentArr = data
})
console.log(this.agentArr)
}
database.service.ts
getAgents(){
const querySnapshot = getDocs(collection(this.db, 'Agents'))
const agentCol: any = []
querySnapshot.then((data) => {
data.docs.forEach((doc) => {
agentCol.push(doc.id)
});
console.log(agentCol)
return agentCol
})
}
im trying to use the return value from the service function in the consent.component.ts, but then i ran into a error ( above see link ) . this was the solution but this is giving a error as well.... Any help appreciated!
Solution
You are trying to subscribe to a function which not return an Observable. The getDocs method returns a promise so you could use an RxJS operator called from, with this operator you can convert an promise to an Observable.
Try something like return from(getDocs(collection(this.db, 'Agents'))
And import import { from } from 'rxjs'
Answered By - Andrei Serguienko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.