Joe Berthelot
Joe Berthelot

Reputation: 735

Angular2 *ngIf is not working properly

HTML

<li class="nav-item">
  <a class="nav-link" routerLink="/register" *ngIf="isLoggedIn">Register</a>
</li>

JS:

var auth = this.af.auth.subscribe( (user) => {
      if (user) {
        // User signed in!
        var uid = user;
        var isLoggedIn = true;
        console.log(uid)
        console.log(isLoggedIn);
      } else {
        // User logged out
        console.log("no user")
        var isLoggedIn = false;
        console.log(isLoggedIn);
      }
    });

The console is logging the true and false values correctly, so var isLoggedIn is correctly changing, but the *ngIf stays hidden no matter what.

Upvotes: 0

Views: 2436

Answers (1)

Panther
Panther

Reputation: 9408

Looks like you are redeclaring your isLoggedIn in the if and else block. Instead you should set it like this.isLoggedin = true and this.isLoggedin = false respectively.

Upvotes: 5

Related Questions