How can you return a value from a promise and include it in a global variable?
I'm trying to make this formed, but to no avail. The global variable is undefined
import { Injectable } from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, CanLoad, Route, Router, RouterStateSnapshot} from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { Auth } from '../providers/auth';
@Injectable()
export class AuthGuard implements CanActivate, CanLoad {
    _check: boolean;
    constructor(private auth: Auth, private router: Router) {
        console.log(this.check());
    }
    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
        return this.check();
    }
    canLoad(Route: Route): Observable<boolean> | boolean {
        return this.check();
    }
    check() {
        this.auth.check().then((user) => {
            if (!user) {
                this._check = null;
            }else {
                this._check = true;
            }
        });
        console.log(this._check)  <---- undefined
        return this._check;
    }
}
 
     
    