Jason - I am now using Restangular and like it so far. It didn't resolve my issue but it does offer a way better experience when communicating with my API.
Eric - Yes the issue was because my controller was resolving before the API call came back. I ended up integrating a really good solution I found on Stackoverflow. I am using Django as my backend framework with Django Rest Framework. This solution allows for me to create groups in Django and utilize those groups as roles inside my site. So far it is working extremely well. http://stackoverflow.com/questions/22537311/angular-ui-router-login-authentication On Saturday, June 21, 2014 3:28:40 PM UTC-6, Jason Girdner wrote: > > Ok I am beating my head into the wall trying to figure out why my service > is returning a undefined value on page load. Below is my service and the > run function I have. I can see from my console log that I am getting the > correct value. But when I log ($rootScope.user) from my app controller I > get undefined. I can see in the Angular inspector that the data I am > trying to get in the controller is in the rootScope but for some reason its > loading undefined before it has a chance to fetch the data. I have played > around for hours with the promise function and can't seem to get it to > work. Any help will be appreciated. > > .service('CurrentUser', function($http, $q) { > this.get = function() { > var deferred = $q.defer(); > var url = '/api/current-user?format=json'; > $http.get(url).success(function(data, status) { > deferred.resolve(data); > }).error(function(data, status) { > deferred.reject(data); > }); > return deferred.promise; > } > }) > .run(function (CurrentUser, $rootScope){ > var promise = CurrentUser.get(); > promise.then(function(data) { > if (data.is_active == false) { > $rootScope.authenticated = false > $rootScope.user = null > console.log($rootScope.authenticated) > } else { > $rootScope.authenticated = true > $rootScope.user = data; > console.log($rootScope.authenticated) > } > }); > }) > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To post to this group, send email to angular@googlegroups.com. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.