P
P
pofigizm2014-05-10 00:14:14
Angular
pofigizm, 2014-05-10 00:14:14

Documentation on $resourceProvider, in particular the standard .get and .save

It just says that they are, but almost nothing about the callback function.
Let me explain what is not clear:
There is a service:

angular.module('myApp')
  .factory('Thing', ['$resource',
    function ($resource) {
      return $resource('/api/things/:id', { id: 'all' }, {} );
    }
  );

And there is a controller:
angular.module('myApp')
  .controller('ThingCtrl', ['$scope', '$location', '$routeParams', 'Thing',
    function ($scope, $location, $routeParams, Thing) {
      
      Thing.get({id: $routeParams.thingId}, function(thing) {
        // Это коллбэк который вызовется после получения данных с сервера. Понял из примеров в доках.
        $scope.thing = thing;
      });

      $scope.save = function() {
        Thing.save({id: $scope.thing._id}, $scope.thing, function() {
          // Этот коллбек нашел тестовым перебором, а хочу увидеть в доках, чтоб понимать нюансы.
          // У меня он срабатывает только при ответе 200 (а может и не только) - не понятно.
        });
      };
    }
  ]);

And at the same time, if not a standard action, but your own (I'm talking about the callback again):
angular.module('myApp')
  .factory('Thing', ['$resource',
    function ($resource) {
      return $resource('/api/things/:id', { id: 'all' }, {
        myaction: {
          method: 'GET',
          params: {
            id:'me'
          }       
      } );
    }
  );

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question