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

前端 未结 4 880
无人及你
无人及你 2020-12-04 15:48

Let\'s say a service like this:

   services.factory(\'User\', function($resource){
        return $resource(\'/rest/usersettings/:username\', {}, {
                 


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 16:26

    User.get( {username: 'bob'} ) does not return your actual data immediately. It returns something will hold your data when the ajax returns. On that (the $promise), you can register an additional callback to log your data.

    You can change your code to:

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

提交回复
热议问题