With $resource you can pre-define the URL for your factory/service to use 
(including variables) as well as the HTTP verbs that each will use:

var addressTypesAPI = '/v1/rest/addresstype/:sid';
var addressTypesResource = $resource(addressTypesAPI, params, {query: { 
method: 'GET'}, create: { method: 'POST'}, update: { method: 'PUT'}, 
remove: { method: 'DELETE'}});

Now, every requests you make with that resource will use the same URL 
(/v1/rest/addresstype/) and variable (:sid if it exists.) This is more 
desirable because you have fewer places in which to keep the same URL, 
resulting in code that is easier to maintain and test. $resource is best 
used in a factory/service and returned as the result of a method call:

var addrList = addressTypesResource.query();
addrList.$promise.then(function(data){
//do something with the data here
});

When appearing in a controller, the call above is SO much cleaner than 
using $http all over the place. Now, yes, you could use $http in a similar 
fashion, but there is more work involved in setting it up, which makes no 
sense when $resource does it much easier.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to