Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hidden state in angular js

This is what I have so far:

example

This is simple drop down based login. What I want to do is to change the login bar to something else when person logs in, but I want current state to be unchanged.

(in this example I'd like the "This is home view" text to be displayed regardless of login state).

My current code structure:

<body  ng-app="pmfApp">
<div>
    <!---  login form and stuff.... ---->
</div>

<nav class="navbar">
<div class="container-fluid">
      <div id="status-buttons" class="text-center">
            <a ui-sref-active="active" ui-sref="home">Home</a>
            <a ui-sref-active="active" ui-sref="about"> About</a>
      </div>
</div>
</nav>

<div ui-view>
    <!--- I have home state view triggered ---->
</div>

So if login goes successful I have something like this:

    $auth.login(credentials).then(function(data) {
            $state.go('???????', {});
    });
like image 777
Andrej Avatar asked Jul 19 '26 06:07

Andrej


1 Answers

It sounds like you want to set a flag in the $scope to track if the user is logged in. You could then use this with ng-if to show and hide the sections you want based on the users login status.

<div ng-if="!loggedInFlag">
    <!---  login form and stuff.... ---->
</div>

<nav class="navbar" ng-if="loggedInFlag">
<div class="container-fluid">
      <div id="status-buttons" class="text-center">
            <a ui-sref-active="active" ui-sref="home">Home</a>
            <a ui-sref-active="active" ui-sref="about"> About</a>
      </div>
</div>
</nav>

<div ui-view>
    <!--- I have home state view triggered ---->
</div>
like image 193
Malkus Avatar answered Jul 22 '26 01:07

Malkus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!