The callback occurs after your second console.log call. Observables are
asynchronous.

On Thu, Jun 30, 2016, 06:44 Simon Azzopardi <[email protected]>
wrote:

> Hi guys,
>
> I am trying to do the AuthGuard for CanActivate and I am trying to get,
> through http, either true or false, if user is logged in.
>
> I have this code in the AuthService.ts
>
>  public subscribeIsUserLoggedIn() : Boolean{
>
>         this.checkIfUserIsLoggedIn().subscribe(
>             result => {
>
>                this. _loginResponseModel = result;
>                  console.log(this._loginResponseModel.IsAuthenticated);
>             }
>
>          );
>
>          console.log(this._loginResponseModel.IsAuthenticated);
>         return this._loginResponseModel.IsAuthenticated;
>     }
>
> The first log is the actual value (true or false) but the other login is
> undefined.
>
> Outside the subscribe, value is being lost.
> Any help pleasE?
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to