Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

18,291 Points

Unable to get $rootscope object on pageload in angularjs

I am using ng-token-auth and devise token-auth in a rails app. Trying to the user object from $rootscope so I can get the user data such as username, first name, last name, etc.

I'm a total noob to AngularJS, so I'm not sure how to solve this

I noticed when i do => console.log($rootScope); I see the user object output => Object {$id: 1, $$childTail: Object, $$childHead: Object, $$prevSibling: null, $$nextSibling: null…}

but when i do console.log($rootScope.user), i get undefined in the output

I did $rootScope.watch and I was able to get the username and set it as local storage, but i believe this is bad practice

Is there a better way to get the user object so i can use it across the platform? Please help!