You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I (initially accidentally) tried to access the user variable in one of my templates ({{user}}) and found that it worked despite not having set the user variable anywhere in my controllers. The object returned was structured as follows:
I thought that somehow ng-token-auth was automatically setting this variable for me which was awesome.
Later, I tried accessing that variable in one of my controllers (console.log(user)) and it said that the variable was undefined. Do you know what's going on? And is there a way to access that user variable on the controller side?
The text was updated successfully, but these errors were encountered:
Try using $auth.user or $rootScope.user in your controller. Make sure to inject $auth or $rootScope ointo your controller. These should allow access to the user object in the controller.
app.controller('MyCtrl', function ($scope, $auth, $rootScope) {
console.log($rootScope.user);
// OR
console.log($auth.user);
});
But just keep in mind that the user object might be empty during the initial run if it's still in the process of being retrieved from the server. I've used an event to grab it once validation is successful in this case.
I (initially accidentally) tried to access the
user
variable in one of my templates ({{user}}
) and found that it worked despite not having set the user variable anywhere in my controllers. The object returned was structured as follows:I thought that somehow ng-token-auth was automatically setting this variable for me which was awesome.
Later, I tried accessing that variable in one of my controllers (
console.log(user)
) and it said that the variable was undefined. Do you know what's going on? And is there a way to access that user variable on the controller side?The text was updated successfully, but these errors were encountered: