I am trying to access user data in a controller via a service. The service returns the object correctly
{
"$id": "9ecadf8e-a233-48ac-bebf-26b50ea2855d",
"$priority": null,
"branch": "London",
"email": "[email protected]",
"firstName": "John",
"lastLogin": 1467975594697,
"lastLoginPrevious": 1467975348837,
"lastName": "Smith",
"role": "Manager"
}
when accessing the data from the controller I can access the $id successfully by using
$scope.userData = UserService.getUserData();
console.log($scope.userData.$id)
but when trying to access any other node such as role
$scope.userData = UserService.getUserData();
console.log($scope.userData.role)
I just get 'undefined' in the console. Obviously I am not doing this correctly but stuck on what I should try next.
Here is my service that retrieves the data from firebase
.service('UserService', ['$location', '$firebaseAuth','$firebaseObject', function ($location, $firebaseAuth, $firebaseObject) {
var userData = '';
var ref = new Firebase("https://firebase-url");
var authData = ref.getAuth();
var userUID = authData.uid;
var userRef = new Firebase("https://firebase-url/Users/" + userUID);
var userData1 = $firebaseObject(userRef);
return {
getUserData: function () {
if (userData == '') {
userData = userData1;
}
return userData;
},
};