0

I have a common HTML where the header got to change after login.

<div class="masthead clearfix">
            <div class="inner">
              <h3 class="masthead-brand"></h3>
              <ul class="nav masthead-nav">
                <li class="active"  ng-show="NotLoggedIn" ><a href="#/login">Login &nbsp;<b>|</b></a></li>
                <li  ng-show="NotLoggedIn"><a href="#/register">Register</a></li>
              <li class="active"  ng-show="LoggedIn" ><a href="#/login">Welcome &nbsp;{{UserName}}<b>|</b></a></li>
                <li  ng-show="LoggedIn" ><a href="#/register">LogOut</a></li>

              </ul>
            </div>
          </div>

          <div ng-view class="mailContent">

          </div>

app.js

app.config(function($routeProvider){

    $routeProvider.when('/',{
        templateUrl : 'template/home.html',
        controller : 'HomeController'
    })
    .when('/login',{
        templateUrl :'template/login.html',
        controller : 'LoginController'

    })
    .otherwise({ redirectTo :'/'});
});

once the login in success NotLoggedIn should hide and LoggedIn should show. How to achieve this scenario.

3 Answers 3

1

ou can use ng-if in AngularJS. You have to assign a boolean value for ng-if. So that the DOM which is having the value false will get removed and the one which is having true will be displayed

<ul class="nav masthead-nav">
  <li class="active"  ng-if="NotLoggedIn" >
        <a href="#/login">Login &nbsp;<b>|</b></a>
  </li>
  <li  ng-if="NotLoggedIn">
        <a href="#/register">Register</a>
  </li>
  <li class="active"  ng-if="LoggedIn" >
        <a href="#/login">Welcome &nbsp;{{UserName}}<b>|</b></a>
  </li>
  <li  ng-if="LoggedIn" >
       <a href="#/register">LogOut</a>
  </li>
</ul>
Sign up to request clarification or add additional context in comments.

Comments

0

Create a service that maintains the login state of the user so that this information can be shared amongst controllers.

Inject the service into the login controller to perform the actual login.

Inject the service into main controller to have access to the state and adjust the user interface accordantly.

Comments

0

You could put the two headers in the top of pages and use "ng-if" directive to enable/disable the desire template. For example:

'LoginController'

$scope.currentSection = "login";


'index.html'

<div ng-if="currentSection === login" ng-include="'views/headerLogOut.html'"></div>
<div ng-if="currentSection !== login" ng-include="'views/headerLogoIn.html'"></div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.