I have created the service below.
app.factory('userProfileFactory', ['FBDB', 'searchParam', function(FBDB, searchParam) {
var personalKey;
return {
userProfile: function() {
var FBref = new Firebase(FBDB).child('items');
FBref.orderByChild('first')
.startAt(searchParam)
.endAt(searchParam)
.once('value', function (snapshot) {
var data = snapshot.val();
personalKey = Object.keys(data)[0];
return(personalKey);
});
return(personalKey);
}
};
}]);
However, when I try to get the results of the value of personalKey in the controller below, I get "undefined":
app.controller('profileCtrl', ['userProfileFactory', function(userProfileFactory) {
console.log(userProfileFactory.userProfile())
}]);
Please advice :)