0

I can´t this navbar to show just one of the navbars, it shows both of them. What am I doing wrong?

View:

    <!-- Logged in -->
    <div ng-show="loggedIn">
      Navbar logged in
    </div>

    <!-- Logged out-->
    <div ng-hide="!loggedIn">
      Navbar logged out
    </div>

  </div>
</nav>

Controller:

.controller('mainCtrl', ['$scope', '$state', 'userService',
  function($scope, $state, userService) {

    $scope.loggedIn = userService.isLoggedIn();

    $scope.login = function() {
      userService.login();
      $state.go('home');
    };

    $scope.logout = function() {
      userService.logout();
      $state.go('login');
    };

  }
]);

3 Answers 3

2

Remove the "!" of the ng-hide:

<!-- Logged out-->
<div ng-hide="loggedIn">
  Navbar logged out
</div>
Sign up to request clarification or add additional context in comments.

Comments

1

You need to update the condition

<div ng-hide="!loggedIn">

to

<div ng-show="!loggedIn">

Comments

1

If you want to fix this with better performance, you don't need to keep the hidden navbar in the DOM, you can use:

<!-- Logged in -->
<div ng-if="loggedIn">
  Navbar logged in
</div>

<!-- Logged out-->
<div ng-if="!loggedIn">
  Navbar logged out
</div>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.