It all depends on what is calling your function. You could, for example, just return the observable. But that would require that the caller supports observavles. Angular 2's "CanActivatec might - I haven't looked into it.
On Thu, Jun 30, 2016, 06:51 Simon Azzopardi <[email protected]> wrote: > Yes I know that, so what I am doing wrong? how can I get that value to > return it back? > > thanks for your reply and you help. > > > On Thursday, June 30, 2016 at 12:48:42 PM UTC+2, Lucas Lacroix wrote: > >> 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. > -- 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.
