Desired Outcome:
I am looking to develop an AngularService that can verify the existence of a specific document and adjust a global variable based on the outcome.
Current Status
The function effectively confirms the presence of the document and updates the global variable within the if/else conditions.
Problem
However, despite the initial success, it consistently returns "undefined".
How do I rectify this issue? Could it be related to function scope?
The Code Snippet for My Service:
export class ProfileFollowService {
//global variable to be modified
followState: boolean;
constructor(private angularFirestore: AngularFirestore) { }
checksFollow(followingID: string, followerID: string): boolean {
const followDoc =
this.angularFirestore.collection(`users/${followingID}/following`).doc(followerID).ref;
followDoc.get().then((doc) => {
if (doc.exists) {
this.followState = true;
} else {
this.followState = false;
}
});
return this.followState;
}
}