Created
July 18, 2014 00:33
-
-
Save cggaurav/78a1ef6e639fa7b90c5c to your computer and use it in GitHub Desktop.
Login state service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('AuthModule', ['localStorage']).factory('AuthState', function(localStorage) { | |
'use strict'; | |
var state = { | |
isLoggedIn: localStorage.get('isLoggedIn') | |
}; | |
return { | |
isLoggedIn: isLoggedIn, | |
}; | |
}); | |
angular.module('controllers', ['AuthState']).factory('SomeCtrl', function($scope, state) { | |
$scope.state = state.isLoggedIn; | |
}); | |
angular.module('controllers', ['AuthState']).factory('SomeCrl', function($scope, state) { | |
$scope.state = state.isLoggedIn; | |
$scope.$watch('state', function() { | |
// your code here | |
console.log('Log in state change'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment