I hope the title of this question makes sense. What i need is a way of storing a reference to a object in a controller and access it in another one.
For example, i have a AppCtrl
where i initiate firebase:
.controller('AppCtrl', function ($scope, $ionicModal, $timeout, $firebase) {
var ref = new Firebase("https://test.firebaseio.com/");
var sync = $firebase(ref);
$scope.db = sync.$asObject();
var authClient = new FirebaseSimpleLogin(ref, function(error, user) {
if (error) {
} else if (user) {
console.log(user);
} else {
// user is logged out
}
});
...
In another controller i want to do authClient.logout()
but authClient
is not available:
.controller('LogoutCtrl', function ($scope, $stateParams, $firebase) {
authClient.logout();
})
Is there a way to access authClient
in the second controller without the need to instantiating FirebaseSimpleLogin
, like grabbing it from a global var?
I'm not sure what is the best approach, maybe is a good idea to instantiate it again..
I'm using firebase
as an example here, but this could be any other class
any ideas?