Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update View/Compoent #11

Closed
larzknoke opened this issue May 16, 2016 · 1 comment
Closed

update View/Compoent #11

larzknoke opened this issue May 16, 2016 · 1 comment

Comments

@larzknoke
Copy link

Hi Ajden,

thx for your nice tutorials. I have a question about your commit 6cab53e.
I put my login() method in a separate injectable service which I call in my component. But my component don't reload after login when I use this.ngZone.run(() => self.loggedIn());
How can I achieve that the component and the ngOnInitwill be update/refresh after the login?

Here my service:

@Injectable()
export class AuthService {

  constructor (private ngZone: NgZone) {
    this.ngZone = ngZone;
  }

 lock = new Auth0Lock('EjqKkgN1EWF0ssIb281Z1jRab4UpLqWy', 'larz.eu.auth0.com');

 login() {
   var self = this;

   this.lock.show((error: string, profile: Object, id_token: string) => {
     if (error) {
       console.log(error);
     }
     // We get a profile object for the user from Auth0
     localStorage.setItem('profile', JSON.stringify(profile));
     // We also get the user's JWT
     localStorage.setItem('id_token', id_token);

     this.ngZone.run(() => self.loggedIn());
   });
 }

my component:

    ngOnInit() {
        if (!tokenNotExpired()) {
            this._auth.login();
        } else {
            this.getAllGuests();
        }
    }

    login() {
        this._auth.login();
    }

    getAllGuests() {
        this._guestService.getAllGuests()
            .subscribe(
                    guests => this.guests = guests,
                    err => console.log(err),
                    () => this.loadList = false
                )

    }  

v
@ajtowf
Copy link
Owner

ajtowf commented May 17, 2016

The reason I do
this.ngZone.run(() => self.loggedIn());
is because my view is evaluating a method on the component called loggedIn() from a *ngIf. To do that from a service that you're not even binding to doesn't make sense.

Also it doesn't look like you have a method called loggedIn() in your service if you'd write your code in typescript it shouldn't compile.

Anyways this is not an issue related to this repo so I'm closing this ticket.

@ajtowf ajtowf closed this as completed May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants