0

I am building my first real world Angularjs application. Object Menus is created in services by following code of my boiler plate code

angular.module('mean.system').factory('Menus', ['$resource', function($resource) {
    return $resource('admin/menu/:name', {
        name: '@name',
        defaultMenu: '@defaultMenu'
    });
}]);

How does this work as in all the turorials I have seen http calls are made by explicitly mentioning the url format and type of request like in following

phonecatServices.factory('Phone', ['$resource',
  function($resource){
    return $resource('phones/:phoneId.json', {}, {
      query: {method:'GET', params:{phoneId:'phones'}, isArray:true}
    });
  }]);
raju
  • 4,788
  • 15
  • 64
  • 119
  • possible duplicate of [Angular.js: service vs provider vs factory?](http://stackoverflow.com/questions/15666048/angular-js-service-vs-provider-vs-factory) – powerc9000 May 27 '14 at 05:50

2 Answers2

1

For better explanation you could check Angular.js $resource docs
Menus factory works practically the same as Phonefactory. It is return $resource object by which you can call a query with name and defaultMenu params. For example:

// set menu and default params
var name = 'admin'
  , default = 'main';

Menus.query({
  name: name,
  defaultMenu: default
}, function(menu) {
   // process responce from the server
   // what it should return?
   $scope.menu = menu;
});
Ruslan Ismagilov
  • 1,360
  • 7
  • 14
1

I think it would be fair to say that this is a question about how $resource works? If that is the case the best place to start is having a look at the docs and the source.

Againt this version of the source, when you invoke $resource(....) you are calling the internal resourceFactory which is building the resource out of the parameters you have provided and some sensible defaults.

ed.
  • 2,696
  • 3
  • 22
  • 25