Created
February 18, 2014 11:18
-
-
Save robwormald/9069085 to your computer and use it in GitHub Desktop.
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
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 | |
} | |
}) |
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
app.controller('someCtrl',function(chromeAuth){ | |
$scope.isLoggedIn = chromeAuth.isLoggedIn; | |
}) |
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
app.controller('someCtrl',function(chromeAuth){ | |
$scope.isLoggedInHereToo = chromeAuth.isLoggedIn; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.