Skip to content

Instantly share code, notes, and snippets.

@robwormald
Created February 18, 2014 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwormald/9069085 to your computer and use it in GitHub Desktop.
Save robwormald/9069085 to your computer and use it in GitHub Desktop.
app.factory('chromeAuth',function(){
var _isLoggedIn = false;
rome.runtime.onMessage.addListener(function(message,sender,respond){
if(message == 'logged_in'){
_isLoggedIn = true;
}
else if(message == 'logged_out'){
_isLoggedIn = false;
}
})
return {
isLoggedIn : _isLoggedIn
}
})
app.controller('someCtrl',function(chromeAuth){
$scope.isLoggedIn = chromeAuth.isLoggedIn;
})
app.controller('someCtrl',function(chromeAuth){
$scope.isLoggedInHereToo = chromeAuth.isLoggedIn;
})
@bluehallu
Copy link

This won't work, isLoggedIn being a boolean (a primitive type) the value is copied, not referenced. $scope.isLoggedIn won't be updated by changes in the service _isLoggedIn var.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment