Just find it really hard to use Firestore to retrieve some information and use it.
Collection: University{
uniID: string,
average_Rating: number
}
Collection: Review{
uniID: string,
Rating: number
userID: string,
}
Collection: User{
userID: string
userName: string
university: string(uniID)
}
Scenario: when the user wants to write a Review, the system assigns User's university to the review's uniID.
I could query the user's document and get its uniID, but how can I save the ID somewhere and use it when I need to?
I tried:
export class reviewServices {
...
userUni: string;
...
construcor(){
this.userUni=""
}
public getUserInfo () {
var userDocRef = this.afs.collection('users').doc(this.userId).ref;
userDocRef.get().then(function(documentSnapshot) {
this.userUni = documentSnapshot.data().uniID
})
}
but it gives the error: Cannot set property 'userUni' of undefined TypeError: Cannot set property 'userUni' of undefined
why why why :(((