After successfully implementing the signIn functionality using Google+ API in my AngularJS web app, I encountered some issues with getting the signOut functionality to work properly.
Within one of my .html files (the Nav-bar), I have a function being called:
<a href="#" ng-click="logout()">SIGN OUT</a>
In the Nav-controller, I am calling the sign out function from the Google API:
$scope.logout = function () {
gapi.auth.signOut();
};
Clicking on the sign out link results in an error message:
Error: [$rootScope:inprog] $apply already in progress
http://errors.angularjs.org/1.2.16/$rootScope/inprog?p0=%24apply
at angular.js:78
...
I'm unsure as to which "$apply" this error is referring to. Am I calling the signOut function correctly? Could it be related to the script placed in the index.html file?
<script>
(function () {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
EDIT: Here is my Auth.js file, which serves as the authentication controller. The code has been adapted from HERE.
$scope.processAuth = function (authResult) {
// Check if authentication was successful.
if (authResult['access_token']) {
// Successful sign in.
$scope.signedIn = true;
// ...
// Do some work [1].
// ...
} else if (authResult['error']) {
// Error during sign in.
$scope.signedIn = false;
// Report error.
}
};
// Process authentication when callback is received.
$scope.signInCallback = function (authResult) {
$scope.$apply(function () {
$scope.processAuth(authResult);
});
};