I'm trying to hide the Sign-In option on the navigation bar once the user logs in successfully. I tried to do it the way explained in the following link, but the Sign-in option is still visible even after the user logs in.
http://stackoverflow.com/questions/22694536/angularjs-ng-hide-with-different-ng-controller
Any help would be greatly appreciated. Thanks in advance.
Here is the application.js and index.html
application.js
myApp.controller('NavbarController', [
'$scope',
'$location',
'$modal',
'$rootScope',
'navservice',
'$window',
function ($scope, $location, $modal, $rootScope, navservice, $window) {
init();
function init() {
navservice.hideSignIn($scope, $location);
};
$scope.doCollapse = function() {
$scope.isCollapsed=!$scope.isCollapsed;
};
$scope.$on('EventFromSigninController',function(data){
$scope.signedin = data.signedin;
});
},
]);
myApp.service('navservice', function () {
this.hideSignIn = function ($scope, $location) {
if (null != username && 0 != username.length &&
null != password && 0 != password.length) {
$scope.signedin = true;
} else {
$scope.signedin = false;
}
};
});
myApp.controller('SignInController', [
'$scope',
'$modal',
'navservice',
'$window',
function ($scope, $modal, navservice, $window) {
var signedIn2 = true;
$scope.dblclick = function() {
//change the local tableHideAlias state
signedIn2 = !signedIn2;
// emit the new hideAlias value
$scope.$emit('EventFromSigninController',{signedIn: signedIn2});
};
},
]);
index.html
<nav class="hidden-xs" role="navigation">
<ul class="nav navbar-nav" data-ng-controller="NavbarController">
<a href="#/home" role="button" class="navbar-brand navbar-band-pad">
<img src="img/sampleimg.png" alt="logo">
</a>
<li data-ng-class="{'active':getClass('/home')}"><a href="#/">Home</a></li>
<li class="dropdown">
<a href="#" role="button" class="dropdown-toggle">
Accounts <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a ng-click="signOut()">Sign Out</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right" data-ng-controller="NavbarController" ng- hide="signedin">
<li id="signinele" data-ng-class="{'active':getClass('/signin')}" data-ng- controller="SignInController" ng-dbclick="dblclick()">
<a href="#/signin">Sign In</a>
</li>
</ul>
</nav>