1

I am trying to build a visual login/logout functionality this way:

1st time when opening the page, the Login link is visible and available, Logout is not. When I do submit Login dissapears and Logout is visible. I tried this with ng-show from angular. The spa page has the common menu:

<ul class="nav navbar-nav">
    <li><a href="/public/Register">Register</a></li>
    <li ng-show="loginlogout"><a href="/public/Login">Login</a></li><!--should be true but it is FALSE-->
    <li ng-show="!loginlogout"><a href="/private/Logout">Logout</a></li>
    <li><a href="/private/UserPage">User</a></li>
</ul>

For setting the loginlogout variable I did it like this:

BetAppModule.controller('HomeController', function ($scope) {

    $scope.loginlogout = true;

});

Although, when I debug in Chrome, loginlogout is set correctly to true, the desired functionality it is not accomplished. Why is loginlogout getting out of scope and it does not stay true as it's set in controller. I also tried using a service. I get the same result.

It works if I use $rootscope, but I hear that this is not recommended. Besides, at some point, I get confused with $rootscope;

Anyhow I would be grateful getting some help. Thank you.

Anubhav
  • 7,138
  • 5
  • 21
  • 33
anne
  • 43
  • 2
  • 8

1 Answers1

1

That should be a scope issue, I guess you are missing ng-controller="HomeController" on your html (view).

Srinivas Paila
  • 817
  • 6
  • 10
  • I don't know what to say about that, because the controller it is set on BettAppModule.config....and it gets there when debugging(or maybe I get it wrong), on home controller.... Maybe I will stick with $rootScope afterall.... Or I will test more, to see if HomeController indeed works as it should... – anne Nov 14 '14 at 13:30
  • If issue still sicks around, create a plunker or fiddle with your problem, so that i can help you on it – Srinivas Paila Nov 14 '14 at 14:47
  • I managed to solve it by explicitly specifying a common controller on the page( kind of the idea of a $rootscope), inherited by Login,Logout,User,Register controllers(specifyed by .config for every route). On this common controller I set $scope.loginlogout and used it on child controllers. Anyhow, u pointed out that there was a problem with my controller so I looked around it. – anne Nov 14 '14 at 15:18