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
Post a Comment