kittu kittu - 1 year ago 96
AngularJS Question

unable to hide logout button after signout using ng-show in angularjs

I have the logout button like this:

<li class="dropdown" data-ng-if="userName">
<a href class="dropdown-toggle clear" data-toggle="dropdown" data-ng-show="userName">
<!-- dropdown -->
<ul class="dropdown-menu>
<li ng-hide="fb_id">
<a ui-sref="app.changePassword">Change Password</a>
<a ui-sref="app.changeProfilePic">Change Profile Picture</a>
<li data-ng-show="userName">
<a ui-sref="access.signout" data-ng-if="userName">Logout</a>
<!-- / dropdown -->

And in the controller:

$scope.logIn = function (user) {
$scope.myPromise = AuthService.login({
'password': user.password,
}).then(function (response) {
$localStorage.userName = response.userName;
$scope.userName = $localStorage.userName;
}, function (error) {
$scope.authError = true;

Sign out controller:

$scope.userName = "";
delete $localStorage.userName;
$rootScope.userName = "";

Doesn't matter I use
it is still showing the logout button and the dropdown.

Answer Source

Try with the below code.

<a ui-sref="access.signout" data-ng-if="userName != ''">Logout</a>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download