bootstrap.js
angular.element(document).ready(function() {
var auth = angular.injector(['auth', 'ngStorage', 'ng']).get('auth');
auth.user().then(function(user){
if (user && user.id) {
angular.bootstrap(document, ['app']);
}
});
});
auth.js
module.provider('auth', [function(){
this.$get = ['$http', '$localStorage', function($http, $storage){
return {
_user: null,
user: function(){
var self = this;
return $http.get('/auth/user').then(function(response){
self._user = response.data;
console.log(self._user); // <- has the user object
return self._user;
});
},
}
}]
}]);
app.js
module.run(function(auth, $state){
console.log(auth._user); // <- is null
});
In my app, when i inject the auth
service, seems like the status is lost - or, the injected auth
is a a new instance (not a singleton).
Can anybody explain why?