I have already read this question How to access JSON Object.$$state.value? and I applied the suggestion, but I still have a promise object as a return of the console.
This is the asynchronous function inside the service:
function getData(myUrl){
    var newref = new Firebase(myUrl);
    return $q(function(resolve, reject){
        newref.once("value", function(snapshot){
            var data = snapshot.val();
            var newUsername = data.username;
            resolve(newUsername);      
        }) 
    });
}
And this is the return of the service:
return{
    getUsername: function(){
        var url = userUrl();
        var promise = getData(url);
        return promise.then(function(whatIneed){
            return whatIneed ;
        })  
    }
};
In the controller I call "getUsername":
var user = CommonService.getUsername();
console.log(user);
I have this return in the console: Console log
I would like to ave the string"Damiano" (the value) insted of the promise object. Why I still have a promise object? Where is the code wrong?
Thanks in advance
 
    