I have the following service
@Injectable()
export class AdminCheckService {
isAdmin: boolean;
uid: string;
constructor(private authService: AuthService, private db: AngularFireDatabase)
{
this.authService.user.subscribe(
(auth) => {
if (auth == null) {
console.log('Not Logged in.');
} else {
this.uid = auth.uid;
}});
db.object('/ownership/questions/' + this.uid ).subscribe( checks => {
this.isAdmin = checks.admin;
console.log(this.isAdmin);
});
}
getAdmin() {
return this.isAdmin;
}
}
When I inject the service and call the getAdmin() function I get an undefined value. I am assuming this is because I have an asynchronous call to the server that does not return before the getAdmin() function is called. How can I make it so that I can make it wait for isAdmin to have a value and return?
Edit: This may seem similar to the How to return from an asynchronous call but it refers to return the value directly from the async call. What I'm trying to accomplish is storing that value in a variable and then returning it when the getAdmin() function is called