I have AuthService and want to use this service in some controllers.
I want to show or hide "log out" button in my front-end, depends on $scope.isLoggedIn.
My front-end code:
<md-button ng-if="isLoggedIn" class="md-button" ng-click="signOut()" aria-label="Logout">
Logout
</md-button>
and my signOut() function:
$scope.signOut = function() {
AuthenticationService.signOut().then(function() {
$location.path('/');
});
};
Authentication service contains functions: signIn(), signOut() and field .isLoggedIn = true|false.
And I want to update my variable in controller, $scope.isLoggedIn depends on AuthenticationService.isLoggedIn. But if I try this:
$scope.isLoggedIn = AuthenticationService.isLoggedIn
it works OK, but only when I load site. So if user is logged in, variable $scope.isLoggedIn is true and if user isn't logged in variable $scope.isLoggedIn is false.
But if AuthenticationService.isLoggedIn change while application runs it doesn't change $scope.isLoggedIn.
Is it possible to keep this reference between service and controller? Or should I do this in another way?