I am using angularfire with the yeoman generator and have a working logout function in my account controller:
$scope.logout = function() { Auth.$unauth(); };
Where Auth is:
(function() {
'use strict';
angular.module('firebase.auth', ['firebase', 'firebase.ref'])
.factory('Auth', function($firebaseAuth, Ref) {
return $firebaseAuth(Ref);
});
})();
That part works great. I would like to make a logout button in the nav bar but since that is in a different scope, I need to make an emitter in my nav controller:
$scope.logout = $scope.$emit('loggedOut');
In my account controller, I listen for emitted signal. Both of these ways do not work:
$scope.$on('loggedOut', function() { Auth.$unauth(); });
$scope.$on('loggedOut', $scope.logout );
Can anyone tell me what I am missing? Thanks!
EDIT- I updated my code but I still have issues:
angular.module('rutileApp')
.controller('AccountCtrl', function ($scope, user, Auth, Ref, $firebaseObject, $timeout) {
$scope.logout = function() { Auth.$unauth(); };
$scope.$on('loggedOut', function(event, msg) {
$scope.logout();
});
});
angular.module('rutileApp')
.controller('NavCtrl', function ($scope, $rootScope) {
$scope.sendLogout = function() {
$rootScope.$broadcast('loggedOut', {msg: 'logging out'});
}
});
I cannot see the broadcasted signal in the AccountCtrl scope even if it is just to console.log something so it isn't a problem with the logout function.