json - AngularJS using $resource service. Promise is not resolved by GET request -


let's service this:

   services.factory('user', function($resource){         return $resource('/rest/usersettings/:username', {}, {             get:    {method: 'get'},             update: {method: 'post'}         });     }); 

so supposed used this:

        scope.user = user.get( {username: 'bob'}  );    //          console.log( json.stringify(scope.user) )       // {"$promise":{},"$resolved":false}  

so, when send request, goes ok, building ur + params:

http://localhost:9000/rest/usersettings/bob 

question, why have: {"$promise":{},"$resolved":false}

if request leads json-response server:{"username":"bob","email":"bob@bobs.com"} i'm expecting have scope.user filled data.

should wait somehow promise ready / resolved ?

user.get( {username: 'bob'} ) not return actual data immediately. returns hold data when ajax returns. on (the $promise), can register additional callback log data.

you can change code to:

   scope.user = user.get( {username: 'bob'}  );    //    scope.user.$promise.then(function(data) {        console.log(data);    }); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -